Page 2 of 2

Re: Select chunk in text field

Posted: Fri Aug 10, 2012 7:12 pm
by jacque
Marek,

The "get" command puts the value into the universal variable "it". In this case, the script gets the value of the the selectedchunk, so "it" contains "word x to y of field z". Using "it" is just shorter to type than this:

if word 4 of the selectedchunk > word 2 of the selectedchunk then...

Using "it" also saves the engine from having to retrieve the value twice. You wouldn't need to use "it", you could use a normal variable instead:

put the selectedchunk into tSel
if word 4 of tSel > word 2 of tSel then...

Mark is correct that my first handler didn't allow for partial word selections. To do that, we need to track the timing of the user selection. If the selection changes within the double-click interval, then it is a double click. This should work:

Code: Select all

local sClickTime

on selectionchanged
  if (the milliseconds - sClickTime) <= the doubleclickinterval then -- it's a double click
    get the selectedchunk
    if word 4 of it > word 2 of it then
      get the number of words in char 1 to (word 2 of the selectedchunk) of me
      select word it of me
    end if
  end if
  put the milliseconds into sClickTime
end selectionchanged
This handler keeps track of the time of the last user click. If the next click is within the time span of a double-click interval then it selects the entire word. Otherwise it does not interfere.

This handler will assume there has been a double-click the first time it is used if you do not initialize sClickTime when the field opens. You should probably add an openField handler that puts the milliseconds into sClickTime.

Re: Select chunk in text field

Posted: Fri Aug 10, 2012 7:42 pm
by Mark
Jacque,

I really like this solution, very elegant, but unfortunately it breaks triple-clicks, which are supposed to select the entire line. Also, if you click on one word and doubleClick just a little too quickly after your first click but too late for a triple click, the first word of the clickLine is seleected instead of the clickWord. I also noticed that your script doesn't work at all if I doubleClick on the w of śmióaśw.

I was playing with your script to see if there is a way to find out how quickly after a doubleClick the third click followed but it takes me too much time right now (am very busy). This would allow you to select lines by triple clicking on them and the "w" would be the only remaining issue. Maybe you can think of a way to do it.

Kind regards,

Mark

Re: Select chunk in text field

Posted: Mon Sep 03, 2012 7:15 pm
by jacque
Just an update. After we had this discussion I reported the bug in the QCC. It was fixed quickly and should work correctly in the next release, which is due out very soon. Unicode editing should work as you'd expect now.

Re: Select chunk in text field

Posted: Mon Sep 03, 2012 10:51 pm
by snm
Good news, thanks Jacque

Marek