OK, so I was close, but didn't get the cigar.

Here's an expanded snippet. The input is in a field called "fInput", the buttons are all in a group, and handled by the group script (saves having many tiny almost identical scripts).

The script  uses the name of the target - but since I would never, ever have a control named as a number, the digit buttons use their label instead.

If the user cannot select a chunk of text then some of this could be shortened.


on mouseup
   if the target = me then
      -- click in the background in the group
      exit mouseup
   end if
   local tChunk
   focus on fld "fInput"
   put the selectedchunk into tChunk
   if the label of the target is a number then
      put the label of the target into the selectedchunk
      exit mouseUp
   end if
   local tFirst, tLast
   put word 2 of tChunk into tFirst
   put word 4 of tChunk into tLast
   switch the short name of the target
      case "go left"
         select before char (min(tFirst, tLast)) of fld "fInput"
         break
      case  "go right"
         select after char (max(tFirst, tLast)) of fld "fInput"
         break
      case "Del"
         -- remove the selection, or the char *after* the ibeam
         if tFirst <= tLast then
            put empty into char tFirst to tLast of fld "fInput"
         else
            put empty into char (tFirst) of fld "fInput"
         end if
         break
      case "BS"
         -- remove the selection, or the char *before* the ibeam
         if tFirst <= tLast then
            put empty into char tFirst to tLast of fld "fInput"
         else
            put empty into char (tFirst-1) of fld "fInput"
         end if
         break
         -- all the other keys !!
      default
   end switch
end mouseup

Alex.


On 05/11/2021 01:39, Roger Guay via use-livecode wrote:
Thanks, Alex. Sorry I didn’t make myself clear. I’m building a calculator stack 
with forward and back arrow buttons and a Delete button. What's the script for 
these buttons?

Roger

On Nov 4, 2021, at 5:53 PM, Alex Tweedly via use-livecode 
<use-livecode@lists.runrev.com> wrote:

Hi Roger,

I'm not sure I properly understand your question.

here's a code snippet the moves the insertion point (in this sample, typing an 
'f' moves it forward, 'b' moves it back). (Note this also works if there is 
some text selected - it moves the insertion to just after the selection, just 
like the arrow key does).

on keydown p
    local t
    switch p
       case  "f"
          put word 4 of the selectedchunk into t
          select after char (t+1) of me
          break
       case "b"
          put word 2 of the selectedchunk into t
          select before char (t-1) of me
          break
    end  switch
end keydown
To then delete the char in front of it, you'd do something like

    put empty into char (t+1) of me

Hope that's close enough to what you were asking, or at least gives you a 
starting place  :-),

Alex.

On 04/11/2021 20:49, Roger Guay via use-livecode wrote:
I simply want to be able to move the insertion iBeam in a focused field left 
and right, one char at a time (just like the left and right arrows keys), and 
then to delete the char in front of it (just like the Delete key). The 
dictionary was again of no use to me. Can someone please provide sample scripts?

Thanks,
Roger
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to