Jump to content

Recommended Posts

Posted
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

Posted

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']);
  • Like 1
  • Upvote 1
Posted
It worked!!!!

 

Very grateful for your help.

 

I've been looking for this on the web for days.

 

Thanks.

  • 3 years later...
Posted

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

Posted
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);
}

 

  • 10 months later...
Posted
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

  • 2 months later...
Posted
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.

 

Posted
3 minutes ago, Sherzod said:

Olá

Você quer inserir texto?..

Yes

Self.edSQL.JSInterface.JSCall('insertAtCursor', ['<' + TUniMenuItem(Sender).Name + '>']);

Posted
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;

 

  • Happy 1
Posted
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 :)

  • Like 1
  • 4 months later...
Posted

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.🙂

Posted
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);
};

 

Posted
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

Posted
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?

Posted
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. 🙂

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...