Silly Text Field Question

Peter Reid preid at reidit.co.uk
Tue Sep 20 18:07:28 EDT 2016


Thanks Mike & Richmond.

Mike – your solution provides the behaviour I'm after but does seem to live on the edge of a runaway loop!  I increased the millisec delay from 1 to 5 to try to reduce the potential for a runaway situation:

local sHilitedelay

on openField
   if sHilitedelay is empty then put the millisec into sHilitedelay
   if the millisec - sHilitedelay > 5 then send "hiliteText" to the target in 0 millisec
end openField

on hiliteText
  select the text of the target
  put the millisec into sHilitedelay
end hiliteText


Richmond – your solution matches the keyboard tabbing behaviour I'm after but not the mouse selection behaviour.


My own further idea was the following in the card script:

on openField
   -- on tabbing into a field highlight its current content:
   hiliteText
end openField

on mouseEnter
   -- on mousing into/across a field highlight its current content:
   hiliteText
end mouseEnter

on hiliteText
   put the id of the target into tID
   if there is a field id tID then
      -- select the text of field objects only:
      select the text of the target
   end if
end hiliteText

The above almost does what I want, but not quite. This method allows the user to use either the tab key on the keyboard or the mouse pointer to select another field. As the new field is selected, its current content is hilited ready to be replaced by any keystrokes.

Note that the user must simply move the mouse pointer into (or across) the new field but NOT click into it. When the user does click the mouse, it behaves normally and places the insertion point in the current content at the position of the mouse pointer at the moment of the click.

As with Mike's approach, the script for this behaviour is in the card script to provide the default behaviour for all fields on the card.

Peter
--
Peter Reid
Loughborough, UK

> On 20 Sep 2016, at 10:14pm, use-livecode-request at lists.runrev.com wrote:
> 
> Date: Tue, 20 Sep 2016 07:07:42 -0600
> From: Mike Bonner <bonnmike at gmail.com>
> To: How to use LiveCode <use-livecode at lists.runrev.com>
> Subject: Re: Silly Text Field Question
> Message-ID:
> 	<CAG1cpSocDM5+65vekuVfd=qKWHER-+=FWNN-9bSvp4sTkHYsBA at mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
> 
> Try this..
> 
> local sHilitedelay
> 
> on openField
> 
> -- sHilitedelay is used to avoid a weird side effect when regaining stack
> focus
> -- by clicking on a field in the card.  If a field other than the
> previously selected
> -- is clicked, it can start a runaway loop. The delay solves this problem.
> -- when experimenting you might put in a "if the shiftkey is down then exit
> to top"
> -- so you can break out of the loop if necessary, though the delay does
> appear to solve it fine.
>   if sHilitedelay is empty then put the millisec into sHilitedelay
> 
> -- use send in time so that all the housekeeping is completed before you
> try to hilite
>   if the millisec - sHilitedelay > 1 then send "hiliteText" to the target
> in 0 millisec
> 
> end openField
> 
> on hiliteText
>   select the text of the target
>   put the millisec into sHilitedelay
> end hiliteText

> 
> On 20 Sep 2016, at 10:14pm, use-livecode-request at lists.runrev.com wrote:
> 
> Date: Tue, 20 Sep 2016 23:29:25 +0300
> From: Richmond <richmondmathewson at gmail.com>
> To: How to use LiveCode <use-livecode at lists.runrev.com>
> Subject: Re: Silly Text Field Question
> Message-ID: <3960ebe8-2e97-572a-941f-b96a97345904 at gmail.com>
> Content-Type: text/plain; charset=windows-1252; format=flowed
> 
> Well, I missed something as well.
> 
> I just put this script in the cardScript:
> 
> on openCard
>    set the autoTab of fld "f1" to true
>    set the autoTab of fld "f2" to true
>    set the autoTab of fld "f3" to true
>    set the autoTab of fld "f4" to true
> end openCard
> 
> and everything works . . . even if I did lose my temper several times.
> 
> https://www.dropbox.com/s/rnnj9rxla17ij8j/Text%20Hop.livecode.zip?dl=0
> 
> Richmond.
> 




More information about the use-livecode mailing list