viaboleto Posted June 7, 2018 Posted June 7, 2018 Hello, How can I insert text where the cursor is in uniMemo? Thanks Quote
Sherzod Posted June 7, 2018 Posted June 7, 2018 Hello, This post can help you: http://forums.unigui.com/index.php?/topic/7497-tab-spacing-inside-unidbmemo/ Quote
viaboleto Posted June 7, 2018 Author Posted June 7, 2018 Thanks a lot for the help Delphi Developer. But I need something like this with uniMemo: UniSession.AddJS (UniHTMLMemo1.JSName + '.insertAtCursor ("' + s + '")'); I need to insert a sequence of characters into a line of the uniMemo. Thanks Quote
Sherzod Posted June 7, 2018 Posted June 7, 2018 But I need something like this with uniMemo: UniSession.AddJS (UniHTMLMemo1.JSName + '.insertAtCursor ("' + s + '")'); I need to insert a sequence of characters into a line of the uniMemo. Try this: 1. MainForm -> Script, add this: Ext.form.field.TextArea.prototype.insertAtCursor = function(txt) { var val = this.value, start = this.inputEl.dom.selectionStart, end = this.inputEl.dom.selectionEnd; this.setValue(val.substring(0, start) + txt + val.substring(end)); this.inputEl.dom.selectionStart = this.inputEl.dom.selectionEnd = start + 1; Ext.defer(function() { this.focus(false); }, 10); } 2. Use like this: UniMemo1.JSInterface.JSCall('insertAtCursor', ['test']); 1 1 Quote
viaboleto Posted June 7, 2018 Author Posted June 7, 2018 It worked!!!! Very grateful for your help. I've been looking for this on the web for days. Thanks. Quote
jackamin Posted June 25, 2021 Posted June 25, 2021 Hello, I was able to insert text at the cursor position, however, I would like the cursor to go to the end of the inserted text afterwards. For example: say my original memo text is '123' and my cursor is between the '2' and the '3'. Now if I insert the string 'test', I want my cursor to be '12test[right here]3' Currently it's going back to the very beginning. Can you please help? Thanks -Jack Quote
Sherzod Posted June 26, 2021 Posted June 26, 2021 6 hours ago, jackamin said: I was able to insert text at the cursor position, however, I would like the cursor to go to the end of the inserted text afterwards. For example: say my original memo text is '123' and my cursor is between the '2' and the '3'. Now if I insert the string 'test', I want my cursor to be '12test[right here]3' Currently it's going back to the very beginning. Can you please help? Hello, Try this: Ext.form.field.TextArea.prototype.insertAtCursor = function(txt) { var val = this.value, start = this.inputEl.dom.selectionStart, end = this.inputEl.dom.selectionEnd; this.setValue(val.substring(0, start) + txt + val.substring(end)); this.inputEl.dom.selectionStart = this.inputEl.dom.selectionEnd = start + txt.length; Ext.defer(function() { this.focus(false); }, 10); } Quote
picyka Posted May 5, 2022 Posted May 5, 2022 On 6/25/2021 at 11:35 PM, Sherzod said: Hello, Try this: Ext.form.field.TextArea.prototype.insertAtCursor = function(txt) { var val = this.value, start = this.inputEl.dom.selectionStart, end = this.inputEl.dom.selectionEnd; this.setValue(val.substring(0, start) + txt + val.substring(end)); this.inputEl.dom.selectionStart = this.inputEl.dom.selectionEnd = start + txt.length; Ext.defer(function() { this.focus(false); }, 10); } very good this tip Quote
风吹小机机 Posted May 6, 2022 Posted May 6, 2022 http://www.9pas.com:8888/?OpenRunForm=CB576A87-96CC-4FE9-8AB3-CA653CC22E17&UserName=AllowLoginFreeUser&PassWord=123&Language=0 Quote
picyka Posted July 6, 2022 Posted July 6, 2022 On 6/25/2021 at 11:35 PM, Sherzod said: Hello, Try this: Ext.form.field.TextArea.prototype.insertAtCursor = function(txt) { var val = this.value, start = this.inputEl.dom.selectionStart, end = this.inputEl.dom.selectionEnd; this.setValue(val.substring(0, start) + txt + val.substring(end)); this.inputEl.dom.selectionStart = this.inputEl.dom.selectionEnd = start + txt.length; Ext.defer(function() { this.focus(false); }, 10); } Ext.ux.form.CodeMirror.prototype.insertAtCursor = function(txt) { var val = this.value, start = this.inputEl.dom.selectionStart, end = this.inputEl.dom.selectionEnd; this.setValue(val.substring(0, start) + txt + val.substring(end)); this.inputEl.dom.selectionStart = this.inputEl.dom.selectionEnd = start + txt.length; Ext.defer(function() { this.focus(false); }, 10); }; Component type TUniSyntaxEdit Can you help me, with the TUniSyntaxEdit component I couldn't get it to work. Quote
picyka Posted July 6, 2022 Posted July 6, 2022 3 minutes ago, Sherzod said: Olá Você quer inserir texto?.. Yes Self.edSQL.JSInterface.JSCall('insertAtCursor', ['<' + TUniMenuItem(Sender).Name + '>']); Quote
Sherzod Posted July 6, 2022 Posted July 6, 2022 1 hour ago, picyka said: Component type TUniSyntaxEdit Can you help me, with the TUniSyntaxEdit component I couldn't get it to work. One possible solution: procedure TMainForm.UniButton1Click(Sender: TObject); begin JSInterface.JSCode(#1'.codeEditor.editor.insertIntoLine('#1'.codeEditor.editor.cursorPosition().line, '#1'.codeEditor.editor.cursorPosition().character, "insert at cursor position...");', UniSyntaxEdit1.JSControl); end; 1 Quote
picyka Posted July 7, 2022 Posted July 7, 2022 11 hours ago, Sherzod said: One possible solution: procedure TMainForm.UniButton1Click(Sender: TObject); begin JSInterface.JSCode(#1'.codeEditor.editor.insertIntoLine('#1'.codeEditor.editor.cursorPosition().line, '#1'.codeEditor.editor.cursorPosition().character, "insert at cursor position...");', UniSyntaxEdit1.JSControl); end; The best support in the world Thanks 1 Quote
Sherzod Posted July 7, 2022 Posted July 7, 2022 14 hours ago, picyka said: Component type TUniSyntaxEdit Solution for UniSyntaxEditEx )) Quote
fabiotj Posted November 28, 2022 Posted November 28, 2022 Hi folks. It works on TUniMemo, but not in TUniEdit/TUniDBedit/TUniDbFormatedNumberEdit causing Ajax error: O13.insertAtCursor is not a function How I can adapt it for use on TUniEdit/TUniDBedit/TUniDbFormatedNumberEdit ? For simulate inputs and backspace. I saw the other post with deleteAtCursor function but work only for a Memo too. ( ) I make a form for TouchScreen terminal and I did my own numeric virtual keyboard and other simple keyboard for text inputs. Thank you in advance for any help.🙂 Quote
Sherzod Posted November 29, 2022 Posted November 29, 2022 5 hours ago, fabiotj said: O13.insertAtCursor is not a function Hello, Try this approach. MainForm.Script -> Ext.form.Text.prototype.insertAtCursor = function (txt) { var val = this.getValue(), start = this.inputEl.dom.selectionStart, end = this.inputEl.dom.selectionEnd; this.setValue(val.substring(0, start) + txt + val.substring(end)); this.inputEl.dom.selectionStart = this.inputEl.dom.selectionEnd = start + txt.length; Ext.defer(function () { this.focus(false); }, 10); }; Quote
fabiotj Posted November 29, 2022 Posted November 29, 2022 7 hours ago, Sherzod said: Hello, Try this approach. MainForm.Script -> Ext.form.Text.prototype.insertAtCursor = function (txt) { var val = this.getValue(), start = this.inputEl.dom.selectionStart, end = this.inputEl.dom.selectionEnd; this.setValue(val.substring(0, start) + txt + val.substring(end)); this.inputEl.dom.selectionStart = this.inputEl.dom.selectionEnd = start + txt.length; Ext.defer(function () { this.focus(false); }, 10); }; Thansk Sherzod, now works on TUniEdit. But I notice that the cursor position is not preserved by going back to the beginning of Edit or Memo. I saw above in this topic that you had already solved this for another user but for some reason it is not working. Maybe I did something wrong? I've attached a simple test case with everything ready to test in both TUniEdit and TUniMemo if you want to see it. InsertAndDeleteAtCursorTests.rar Quote
Sherzod Posted November 29, 2022 Posted November 29, 2022 2 minutes ago, fabiotj said: But I notice that the cursor position is not preserved by going back to the beginning of Edit or Memo. Sorry, can you please explain in more details? Quote
fabiotj Posted November 29, 2022 Posted November 29, 2022 On 6/25/2021 at 4:20 PM, jackamin said: Hello, I was able to insert text at the cursor position, however, I would like the cursor to go to the end of the inserted text afterwards. For example: say my original memo text is '123' and my cursor is between the '2' and the '3'. Now if I insert the string 'test', I want my cursor to be '12test[right here]3' Currently it's going back to the very beginning. Can you please help? Thanks -Jack Ok, is the same problem above reported by Jack. 🙂 Quote
Sherzod Posted November 29, 2022 Posted November 29, 2022 I couldn't reproduce. Works for me... Quote
fabiotj Posted November 29, 2022 Posted November 29, 2022 Works in my test case project? If yes, think that I'm do somethink wrong. Please, look the attached video. InsertDeleteAtCursor.mp4 Quote
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.