Page 1 of 1

How to select all text (cmd+a)?

Posted: Sat Apr 11, 2015 11:58 am
by gtheus
I'm stuck with the following problem (LC 7.0.4 on Mac): I have several text fields on my card. I'd like to give the users the possibility to mark all content of a text field as selected by pressing cmd+a on the keyboard, if the cursor is within the text field. I added a menu option "mark all" in MenuBuilder and assigned it the shortcut "cmd+a". I entered the following code in MenuBuilder:

Code: Select all

on menuPick pWhich
   switch pWhich

      [...deleted...]

      case "mark all"
         select the text of the target
         break
   end switch
end menuPick
This code has a behaviour I don't understand: If I have preselected some text in a text field, this selection gets cut after entering cmd+a (and is copied to the clipboard). If I just click into a text field and then enter cmd+a, nothing happens. How can I mark all of the text as selected in a focused text field?

Re: How to select all text (cmd+a)?

Posted: Sat Apr 11, 2015 12:36 pm
by jmburnod
Hi gTheus,

I think you have to put the name of "clicked field" at openfield into a variable sMyField
and replace

Code: Select all

 select the text of the target
with

Code: Select all

select the text of fld sMyField
Best regards
Jean-Marc

Re: How to select all text (cmd+a)?

Posted: Sat Apr 11, 2015 3:39 pm
by gtheus
Hi Jean-Marc, thank you for the hint. I was wrong with "target", which refers - in my case - to the menu entry and not to the focused text field, right? After switching to your solution it works great. :-)
Best, Gian-Reto.

Re: How to select all text (cmd+a)?

Posted: Sat Apr 11, 2015 5:38 pm
by jacque
You don't need a variable. Use "the selectedField" like this :

Code: Select all

if the selectedField is not empty then select the text of the selectedField

Re: How to select all text (cmd+a)?

Posted: Sun Apr 12, 2015 9:03 am
by gtheus
Jacque, thank you. Entered into my code snippet collection to hopefully be never forgotten. :-)