Page 1 of 1
mouseChunk in a loop
Posted: Sun Jun 09, 2019 9:28 pm
by rcmills
I want to select text for highlighting in a field. It seems most reasonable to use the mouseChunk function recursively while waiting for the mouse to be up. But it seems that the mouseChunk only returns an initial set of values when the mouseDown occurs, and not agains until another mouseDown. Is there any way to get continuing values while the mouse is still down?
With this code, the text color changes when I press the option key or not, but only in the word initially under the mouse, and does not move to (or extend to - what I really want) other words in the field.
Code: Select all
if the mouse is down
then
put the mouseChunk into theChunk
repeat until the mouse is up
get the mouseChunk
put min(word 2 of it,word 2 of theChunk) into word 2 of theChunk
put max(word 4 of it,word 4 of theChunk) into word 4 of theChunk
if the optionKey is down
then
set the textColor of theChunk to blue
else
set the textColor of theChunk to red
end if
end repeat
end if
Re: mouseChunk in a loop
Posted: Sun Jun 09, 2019 9:38 pm
by SparkOut
I'm not sure what you're trying to do, but wouldn't you be better off with the "selectionChanged" message and changing the colour of the "selectedChunk"?
Re: mouseChunk in a loop
Posted: Mon Jun 10, 2019 2:05 am
by rcmills
Thanks,
I see what you are saying, but I am trying to do this in a locked text field. I should have stated that in the original post, but no changes are allowed in the field, other than code driven.
Re: mouseChunk in a loop
Posted: Mon Jun 10, 2019 2:10 am
by rcmills
The red and blue if/then segment is just there for my testing. I was trying to see if the loop was hanging up on the get mouseChunk statement, but it is not. It's just that the mouseChunk doesn't ever update after the first time in the loop.
Re: mouseChunk in a loop
Posted: Mon Jun 10, 2019 4:09 am
by bogs
rcmills wrote: ↑Mon Jun 10, 2019 2:05 am
I see what you are saying, but I am trying to do this in a locked text field. I should have stated that in the original post, but no changes are allowed in the field, other than code driven.
SelectedChunk works in a locked field, not sure if your aware of that.
- Locked and loaded...
Re: mouseChunk in a loop
Posted: Mon Jun 10, 2019 10:27 am
by jmburnod
Hi rcmills ,
I am trying to do this in a locked text field.
Yes You can. You have to set the traversalon of your fld to true ("focus with keyboard" in inspector on a Mac).
Best regards
Jean-Marc
Re: mouseChunk in a loop
Posted: Mon Jun 10, 2019 10:40 am
by [-hh]
Summarizes partially the above. Works with a locked field.
Code: Select all
on mouseDown
colorMe
end mouseDown
on colorMe
if the mouse is up then exit colorMe
if the optionkey is down then put "blue" into cc
else put "red" into cc
set textcolor of char 1 to -1 of me to "black" -- reset color
set textcolor of the selectedChunk to cc
send "colorMe" to me in 32 millisecs
end colorMe
Re: mouseChunk in a loop
Posted: Mon Jun 10, 2019 5:58 pm
by rcmills
Thanks, that worked - in the development environment.
But now, how can I make it work in iOS, with a locked native scroller text field? I have set a flag to stop the scrolling in the scrollerDidScroll and scrollerEndDecelerate handlers to allow selection motion without scrolling. This does stop the scrolling and allows text selection, but only allows selecting of one or two characters of the text, and then my code won't progress to the answer dialog box asking for a color.
Code: Select all
on mouseDown
put true into scrollLock
end mouseDown
on selectionChanged
wait until the mouse is up
put the selectedChunk into tChunk
if word 2 of tChunk < word 4 of tChunk
then
answer "Choose color" with "Red" or "Blue" or "Yellow" or "Clear" as sheet
if it = "Clear" then get the effective backgroundColor of me
set the backgroundcolor of tChunk to it
select empty
end if
put false into scrollLock
end selectionChanged
Re: mouseChunk in a loop
Posted: Tue Jun 11, 2019 1:07 pm
by rcmills
It appears to me that in a locked native iOS scroller field, the selectionChanged message is not being sent, unless the amount of text in the field is not great enough to need scrolling. The code in my last post works fine then, but if the field scrolls, the on selectionChanged handler is never called.
Is there any way to work around this?