mouseChunk in a loop

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
rcmills
Posts: 42
Joined: Wed Nov 21, 2018 8:27 pm

mouseChunk in a loop

Post by rcmills » Sun Jun 09, 2019 9:28 pm

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	

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: mouseChunk in a loop

Post by SparkOut » Sun Jun 09, 2019 9:38 pm

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

rcmills
Posts: 42
Joined: Wed Nov 21, 2018 8:27 pm

Re: mouseChunk in a loop

Post by rcmills » Mon Jun 10, 2019 2:05 am

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.

rcmills
Posts: 42
Joined: Wed Nov 21, 2018 8:27 pm

Re: mouseChunk in a loop

Post by rcmills » Mon Jun 10, 2019 2:10 am

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.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: mouseChunk in a loop

Post by bogs » Mon Jun 10, 2019 4:09 am

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.
Selection_001.png
Locked and loaded...
Image

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: mouseChunk in a loop

Post by jmburnod » Mon Jun 10, 2019 10:27 am

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
https://alternatic.ch

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: mouseChunk in a loop

Post by [-hh] » Mon Jun 10, 2019 10:40 am

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
shiftLock happens

rcmills
Posts: 42
Joined: Wed Nov 21, 2018 8:27 pm

Re: mouseChunk in a loop

Post by rcmills » Mon Jun 10, 2019 5:58 pm

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

rcmills
Posts: 42
Joined: Wed Nov 21, 2018 8:27 pm

Re: mouseChunk in a loop

Post by rcmills » Tue Jun 11, 2019 1:07 pm

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?

Post Reply

Return to “Talking LiveCode”