Jump to content

TUniEdit SelStart


droider

Recommended Posts

  • 3 weeks later...

Can you try this simple implementation ?!:

 

1. MainForm -> Script:

function selectSE(id, start, end) {
    var input = document.getElementById(id);
    if ('selectionStart' in input) {
        input.selectionStart = start;
        input.selectionEnd = end;
        input.focus();
    } else { // Internet Explorer before version 9
        var inputRange = input.createTextRange();
        inputRange.moveStart("character", 1);
        inputRange.collapse();
        inputRange.moveEnd("character", 1);
        inputRange.select();
    }
}

2. How to use, for example:

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  UniSession.AddJS('selectSE('+UniEdit1.JSName+'.inputEl.id, 0, 2)');
end;

Best regards,

Link to comment
Share on other sites

Hi,

 

I don't know why, on a minimalist testCase project, I have no issue and highlighting is working properly, but on my own project, function selectSE is never recognize .. any idea ; workaround ?  :(

 

Ok, try this approach:

 

1. MainForm -> Script:

Ext.form.field.Text.prototype._selectSE = function(start, end) {
    var input = document.getElementById(this.inputEl.id);
    if ('selectionStart' in input) {
        input.selectionStart = start;
        input.selectionEnd = end;
        input.focus();
    } else { // Internet Explorer before version 9
        var inputRange = input.createTextRange();
        inputRange.moveStart("character", 1);
        inputRange.collapse();
        inputRange.moveEnd("character", 1);
        inputRange.select();
    }
}

2. Use like this:

UniEdit1.JSInterface.JSCall('_selectSE', [0, 2]);

Best regards,

Link to comment
Share on other sites

  • 2 weeks later...

Hello Lion ! (:

 

Sorry I didn't have time until now to handle this problematic! (;

 

This solution is better because I don't have the same issue: _selectSE is always recognize, but my text is not selected neither highlighted ! :(

This solution still work properly on my minimalist test project.

Any idea or workaround why text is not selected ?  :wacko:

 

Best regards,

Link to comment
Share on other sites

  • 2 weeks later...

I did manage to select and highlight my text: I was launching highlight after a onButtonClick event :

begin

  uniEdit1.Text := 'This is my TEXT to be selected';

  uniEdit1.JSInterface.JSCall('_selectSE', [12, 16]);

end;

 

Apparently the first line was affecting the JS call because nothing was higlighted, so I did the same thing but directly in JS:

 

Ext.form.field.Text.prototype._selectSE = function(text){
   var input = document.getElementById(this.inputEl.id);
   input.value = text;
   start = text.search("VALEUR");
   end = start + 6;
   if ('selectionStart' in input) {
      input.selectionStart = start;
      input.selectionEnd = end;
      input.focus();
      input.focus();
   } else {
      var inputRange = input.createTextRange();
      inputRange.moveStart("character", 1);
      inputRange.collapse();
      inputRange.moveEnd("character", 1);
      inputRange.select();
   }
}
Calling the JS method as you told me :
EFilter.JSInterface.JSCall('_selectSE', ['Ceci est la VALEUR à souligner']);
 
Best regards,
 
Link to comment
Share on other sites

  • 1 year later...

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