How to select all text (cmd+a)?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
gtheus
Posts: 13
Joined: Sun Jan 27, 2008 11:44 am

How to select all text (cmd+a)?

Post 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?
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2734
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

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

Post 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
https://alternatic.ch
gtheus
Posts: 13
Joined: Sun Jan 27, 2008 11:44 am

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

Post 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.
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

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

Post 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
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
gtheus
Posts: 13
Joined: Sun Jan 27, 2008 11:44 am

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

Post by gtheus »

Jacque, thank you. Entered into my code snippet collection to hopefully be never forgotten. :-)
Post Reply