Luciano França Posted July 5, 2023 Share Posted July 5, 2023 I have tried the following approaches but none work function beforeInit(sender, config) { config.keyMap = { ENTER: { handler: function() { ajaxRequest(sender, '_ENTER', []); } }, F2: { handler: function() { ajaxRequest(sender, '_F2', []); } }, ESC: { handler: function() { ajaxRequest(sender, '_ESC', []); } }, DELETE: { handler: function() { ajaxRequest(sender, '_DELETE', []); } } } } procedure TMainForm.UniSyntaxEdit1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = '_ENTER' then begin ShowMessage('You have pressed the <b>ENTER</b> key.'); end; if EventName = '_F2' then begin ShowMessage('You have pressed the <b>F2</b> key.'); end; if EventName = '_ESC' then begin ShowMessage('You have pressed the <b>ESC</b> key.'); end; if EventName = '_DELETE' then begin ShowMessage('You have pressed the <b>DELETE</b> key.'); end; end; And function keydown(sender, e, eOpts) { if (e.getKey() == 13 ) { alert('Enter'); ajaxRequest(sender, 'doEnter', []); } } procedure TMainForm.UniSyntaxEdit1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = 'doEnter' then begin ShowMessage('You have pressed the <b>ENTER</b> key.'); end; End; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 5, 2023 Share Posted July 5, 2023 @Luciano França How to detect OnkeyDown events "UniSyntaxEdit" We will try to check. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 6, 2023 Share Posted July 6, 2023 Hello @Luciano França 7 hours ago, Sherzod said: "UniSyntaxEdit" Firstly, it is better to use UniSyntaxEditEx instead. Secondly, I will try to give a solution based on which component you will use. Quote Link to comment Share on other sites More sharing options...
风吹小机机 Posted July 8, 2023 Share Posted July 8, 2023 UniURLFrame + codemirror-5.25 beautiful You can control it any way you want Quote Link to comment Share on other sites More sharing options...
Luciano França Posted July 8, 2023 Author Share Posted July 8, 2023 16 hours ago, 风吹小机机 said: UniURLFrame + codemirror-5.25 beautiful You can control it any way you want what is that ? a component? can you give me more explanations with examples and pass the link of the same. Grateful. Quote Link to comment Share on other sites More sharing options...
Luciano França Posted July 8, 2023 Author Share Posted July 8, 2023 On 7/6/2023 at 2:11 AM, Sherzod said: Hello @Luciano França Firstly, it is better to use UniSyntaxEditEx instead. Secondly, I will try to give a solution based on which component you will use. Using the "UniSyntaxEditEx" component I can capture the Keys but I cannot selectionStart And selectionEnd This approach doesn't work procedure TMainForm.UniFormCreate(Sender: TObject); begin with UniSyntaxEditEx1.JSInterface do Begin JSAddListener('blur', 'function(){ajaxRequest(this, "_blur", ["cpos="+this.inputEl.dom.selectionStart])}'); JSAddListener('blur', 'function(){ajaxRequest(this, "_blur", ["lpos="+this.inputEl.dom.selectionEnd])}'); End; end; procedure TMainForm.UniSyntaxEditEx1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = '_blur' then begin (Sender as TUniSyntaxEditEx).CustomAttribs.Values['cpos'] := Params.Values['cpos']; (Sender as TUniSyntaxEditEx).CustomAttribs.Values['lpos'] := Params.Values['lpos']; End; end; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 9, 2023 Share Posted July 9, 2023 17 hours ago, Luciano França said: Using the "UniSyntaxEditEx" component I can capture the Keys but I cannot Are you trying to search the forum? Quote Link to comment Share on other sites More sharing options...
Luciano França Posted July 9, 2023 Author Share Posted July 9, 2023 2 hours ago, Sherzod said: Are you trying to search the forum? I've already seen this topic and it doesn't help me. Because what I need is to get the "get" positions As I mentioned, I need to know the selectionStart and selectionEnd Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 10, 2023 Share Posted July 10, 2023 14 hours ago, Luciano França said: I've already seen this topic and it doesn't help me. Because what I need is to get the "get" positions As I mentioned, I need to know the selectionStart and selectionEnd On 7/5/2023 at 9:08 AM, Sherzod said: and analyze the solutions Quote Link to comment Share on other sites More sharing options...
Luciano França Posted July 10, 2023 Author Share Posted July 10, 2023 12 hours ago, Sherzod said: This Post is mine and the codes posted don't work with "UniSyntaxEdit" this code below does not work procedure TMainForm.UniFormCreate(Sender: TObject); begin with UniSyntaxEditEx1.JSInterface do JSAddListener('blur', 'function(){ajaxRequest(this, "_blur", ["cpos="+this.inputEl.dom.selectionStart])}'); end; procedure TMainForm.UniSyntaxEditEx1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = '_blur' then (Sender as TUniSyntaxEditEx).CustomAttribs.Values['cpos'] := Params.Values['cpos']; end; Quote Link to comment Share on other sites More sharing options...
Luciano França Posted July 11, 2023 Author Share Posted July 11, 2023 From what I understand the "UniSyntaxEditEx" component doesn't have "SelectionStart" so how could I get the line and character where the cursor is? How could I return using this information codeEditor.editor.cursorPosition().character codeEditor.editor.cursorPosition().line Can you create an example for me because I didn't find anything on the forum that returns this information Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 11, 2023 Share Posted July 11, 2023 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 11, 2023 Share Posted July 11, 2023 3 hours ago, Luciano França said: How could I return using this information codeEditor.editor.cursorPosition().character codeEditor.editor.cursorPosition().line And, remind me again, what's it all for !? Quote Link to comment Share on other sites More sharing options...
Luciano França Posted July 11, 2023 Author Share Posted July 11, 2023 7 hours ago, Sherzod said: And, remind me again, what's it all for !? So I need a way to return these two pieces of information from "line" and "ch" could you post a "Get" capture code for me. The reason is that in several situations in VCL I used "CaretPos.X" and "CaretPos.Y" to know where the mouse cursor is With "UniMemo" I achieved this using "selectionStart" but with "UniSyntaxEditEx" there is no "selectionStart" so I need another way to achieve this. Ps. I already tried to adapt this code that you posted above but I couldn't return these two information "line" and "ch" function afterCreate(sender) { sender.insertTextAtCursor = function(str) { var editor = this.codeEditor; var selection = editor.getSelection(); if (selection.length > 0) { editor.replaceSelection(str); } else { var doc = editor.getDoc(); var cursor = doc.getCursor(); var pos = { line: cursor.line, ch: cursor.ch }; doc.replaceRange(str, pos); } } } Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 11, 2023 Share Posted July 11, 2023 4 minutes ago, Luciano França said: there is no "selectionStart" What do you mean by saying this? Why do you need it, to insert text or what? If it's an insert then this works also for UniSyntaxEditEx. Quote Link to comment Share on other sites More sharing options...
Luciano França Posted July 11, 2023 Author Share Posted July 11, 2023 14 minutes ago, Sherzod said: What do you mean by saying this? Why do you need it, to insert text or what? If it's an insert then this works also for UniSyntaxEditEx. If the Colleague can please assemble a Code for me that returns me to "Line" and "Ch" As I already mentioned, I have several situations, which make it difficult to explain here all the places of my ERP that I need. If you can put me a code I would be very grateful. I tested something like this no longer works procedure TMainForm.UniButton1Click(Sender: TObject); begin with UniSyntaxEditEx1, UniSyntaxEditEx1.JSInterface do Begin JSCode('Ext.defer(function(){ajaxRequest(' + JSName + ', "getSelection", ["selectedText="+' + JSName + .codeEditor.getDoc().getCursor().line])}, 0);') end; End; procedure TMainForm.UniButton2Click(Sender: TObject); begin with UniSyntaxEditEx1, UniSyntaxEditEx1.JSInterface do Begin JSCode('Ext.defer(function(){ajaxRequest(' + JSName + ', "getSelection", ["selectedText="+' + JSName + .codeEditor.getDoc().getCursor().ch])}, 0);') end; End; procedure TMainForm.UniSyntaxEditEx1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = 'getSelection' then UniEdit1.Lines.Text := Params.Values['selectedText']; end; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 11, 2023 Share Posted July 11, 2023 I don't know what and how you are doing, but the solution above works for me. procedure TMainForm.UniButton4Click(Sender: TObject); begin with UniSyntaxEditEx1, UniSyntaxEditEx1.JSInterface do Begin JSCode('Ext.defer(function(){ajaxRequest(' + JSName + ', "getSelection", ["selectedText="+' + JSName + '.codeEditor.getDoc().getCursor().line])}, 0);') end; end; procedure TMainForm.UniSyntaxEditEx1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = 'getSelection' then UniEdit2.Text := Params.Values['selectedText']; end; Quote Link to comment Share on other sites More sharing options...
Luciano França Posted July 11, 2023 Author Share Posted July 11, 2023 51 minutes ago, Sherzod said: I don't know what and how you are doing, but the solution above works for me. procedure TMainForm.UniButton4Click(Sender: TObject); begin with UniSyntaxEditEx1, UniSyntaxEditEx1.JSInterface do Begin JSCode('Ext.defer(function(){ajaxRequest(' + JSName + ', "getSelection", ["selectedText="+' + JSName + '.codeEditor.getDoc().getCursor().line])}, 0);') end; end; procedure TMainForm.UniSyntaxEditEx1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = 'getSelection' then UniEdit2.Text := Params.Values['selectedText']; end; My problem is that I need to Get the "Line" and the "Ch" from 3 components "TUniMemo", "TUniSyntaxEditEx" and "TUniHTMLMemo"" This code I posted above I was testing a "UniHTMLMemo" however this code only works with "UniSyntaxEditEx" That way I'm almost there: With "TUniMemo" I can with "SelectionStart" with UniMemo1.JSInterface do JSAddListener('blur', 'function(){ajaxRequest(this, "_blur", ["cpos="+this.inputEl.dom.selectionStart])}'); With "TUniSyntaxEditEx" I can with with UniSyntaxEditEx1, UniSyntaxEditEx1.JSInterface do Begin JSCode('Ext.defer(function(){ajaxRequest(' + JSName + ', "getSelection", ["selectedText="+' + JSName + '.codeEditor.getDoc().getCursor().ch])}, 0);') end; Now how to do with "TUniHTMLMemo" ? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 11, 2023 Share Posted July 11, 2023 Sorry, then I did not understand your case, and I think I can not help you with this question. Quote Link to comment Share on other sites More sharing options...
Luciano França Posted July 11, 2023 Author Share Posted July 11, 2023 1 hour ago, Sherzod said: Sorry, then I did not understand your case, and I think I can not help you with this question. I will try to explain better I already managed to get the "line" and "Ch" of two components "TUniMemo" and "TUniSyntaxEditEx" because neither of these two approaches works with "TUniHTMLMemo" ? // Error with UniHTMLMemo1.JSInterface do JSAddListener('blur', 'function(){ajaxRequest(this, "_blur", ["cpos="+this.inputEl.dom.selectionStart])}'); // Error with UniHTMLMemo1, UniHTMLMemo1.JSInterface do Begin JSCode('Ext.defer(function(){ajaxRequest(' + JSName + ', "getSelection", ["selectedText="+' + JSName + '.codeEditor.getDoc().getCursor().ch])}, 0);') end; // Error with UniHTMLMemo1, UniHTMLMemo1.JSInterface do Begin JSCode('Ext.defer(function(){ajaxRequest(' + JSName + ', "getSelection", ["selectedText="+' + JSName + '.htmlEditor.getDoc().getCursor().ch])}, 0);') end; // Error with UniHTMLMemo1, UniHTMLMemo1.JSInterface do Begin JSCode('Ext.defer(function(){ajaxRequest(' + JSName + ', "getSelection", ["selectedText="+' + JSName + '.getDoc().getCursor().ch])}, 0);') end; Quote Link to comment Share on other sites More sharing options...
风吹小机机 Posted July 15, 2023 Share Posted July 15, 2023 UGFrame 简单介绍-腾讯云开发者社区-腾讯云 (tencent.com) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.