Jump to content

Cursor Position in TuniMemo


mayusod

Recommended Posts

Hi,

 

Try:

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  UniSession.AddJS('var el = document.getElementById("'+UniMemo1.JSName+'_id-inputEl"); val = el.value; alert(val.slice(0, el.selectionStart).length)');
end;

Best regards!

Link to comment
Share on other sites

  • 6 years later...

Sorry, I could not found it. I already saw 100+ topics, but have no success.

I've found my own old topic:

With link here:

But I don't understand how it could help me.

I need this behaviour: push a button on the form, do request to a TUniMemo and get the line where the text cursor curently located in the TUniMemo. Thank you!

Link to comment
Share on other sites

25 minutes ago, Tokay said:

I need this behaviour: push a button on the form, do request to a TUniMemo and get the line where the text cursor curently located in the TUniMemo. Thank you!

For example, one possible solution.

1. 

procedure TMainForm.UniFormCreate(Sender: TObject);
begin
  with UniMemo1.JSInterface do
    JSAddListener('blur', 'function(){ajaxRequest(this, "_blur", ["cpos="+this.inputEl.dom.selectionStart])}');

end;

2. 

procedure TMainForm.UniMemo1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if EventName = '_blur' then
    (Sender as TUniMemo).CustomAttribs.Values['cpos'] := Params.Values['cpos'];

end;

3. Usage:

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  ShowMessage(UniMemo1.CustomAttribs.Values['cpos'])
end;

 

Link to comment
Share on other sites

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