Select text on focus

Hi,

So I’m trying to figure out how to auto-select all the text in my text area when the user clicks on it, but so far no luck.

I feel like I’m probably missing something obvious, any thoughts on what it is?

Thanks

Eric

Hello!

this could help you out :slight_smile:

Thanks for the heads up!

It seems a little different than what I’m trying to do though.

Basically what I’m lookinf for is that when a User single-clicks in the text area for the first time all the text becomes highlighted (in this case “Enter Dialog Here”), so that they can immediately start replacing it with their own.

There’s no built-in function to accomplish this, but you should be able to build that functionality yourself simply. Basically try the following in your OnGUI function:

  1. Get an ID for your text field (using GUIUtilty.GetControlID ())
  2. Use Event.GetTypeForControl () to detect clicks onto the TextField
  3. When you detect a click, use GUI.FocusControl() to select the text field.
  4. Call Event.use, so the normal processing of the event by the TextField is overridden.