Search Unity

TextMesh Pro Move cursor to end of text

Discussion in 'UGUI & TextMesh Pro' started by kryzodoze, May 11, 2018.

  1. kryzodoze

    kryzodoze

    Joined:
    Nov 6, 2013
    Posts:
    17
    Hey there Stefan and team, question for you. We have the use case of programatically selecting a TMP_InputField component and setting the cursor at the end so somebody can start typing from the end.

    Both Select() and ActivateInputField() successfully give focus to the input field but select all of the text. Setting caretPosition after that doesn't seem to do anything. Tried both the MoveTextEnd() and MoveToEndOfLine() methods with no success either.
     
  2. kryzodoze

    kryzodoze

    Joined:
    Nov 6, 2013
    Posts:
    17
    Turns out there's an option in "Control Settings" on the input field component for 'OnFocus - Select All', just had to un-check that. :D
     
  3. kryzodoze

    kryzodoze

    Joined:
    Nov 6, 2013
    Posts:
    17
    Well, I still haven't solved the "move cursor to end of text" issue, but I solved the "it's highlighting all text when selected" problem.
     
  4. PSchaussPlaya

    PSchaussPlaya

    Joined:
    Mar 2, 2018
    Posts:
    8
    inputField.MoveToEndOfLine(false, false);
    works for me.
    You may try to execute it with a delay. E.g. in a coroutine after a
    yield return new WaitForEndOfFrame();
    or in LateUpdate.
     
    Reyan62 likes this.
  5. OSagioma

    OSagioma

    Joined:
    May 12, 2015
    Posts:
    13
    Doesn't do nothing for me :(
     
  6. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    3,945
    This function should be working as intended as I tested it last night again.

    Please provide the full scripts where you are trying to use this function. See if you can produce a simple repro script for me to use for testing.
     
  7. OSagioma

    OSagioma

    Joined:
    May 12, 2015
    Posts:
    13
    I have fixed this the other day. A friend of mine provided an alternative.
     
    Stephan_B likes this.
  8. rcaettano

    rcaettano

    Joined:
    Dec 11, 2012
    Posts:
    5
    Kinda old, but LateUpdate worked for me, thanks !
     
  9. dr_vr

    dr_vr

    Joined:
    Dec 8, 2017
    Posts:
    2
    Use inputField.MoveToEndOfLine(false, true) if you wanna go to the end of all of the text.
     
unityunity