Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question TextField doesn't pan to the last character when the text is larger than the inputbox

Discussion in 'UI Toolkit' started by __SHADE, Jun 26, 2023.

  1. __SHADE

    __SHADE

    Joined:
    Jun 2, 2015
    Posts:
    12
    Hi all,

    I am changing the text inside of a TextField, but I am having issues where it doesn't show the last character of the value. How to I force it to pan to the right (similar to if a user were to type it manually)?

    upload_2023-6-26_16-42-54.png

    Thanks,
    Shade
     
  2. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    437
    Hi @__SHADE, are you updating the text programmatically and would you like to show the cursor at the end ?

    If it's the case, you can update the cursor position using this API:
    Code (CSharp):
    1. textField.cursorIndex = textField.selectIndex = textField.text.Length;
     
  3. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    437
    Note that there are a whole lot of utility APIs under these:

    Code (CSharp):
    1.  
    2. textField.textSelection
    3. textField.textEdition
    4.  
     
  4. __SHADE

    __SHADE

    Joined:
    Jun 2, 2015
    Posts:
    12
    Hi Hugo, which UIToolKit version are you using? I am on Unity 2021.3.24f1. Both the cursorIndex and selectIndex is get only. I tried

    textField.SelectRange(textField.text.Length, textField.text.Length);
    as I think it should do the same thing as what you suggested but it is still not panning to the right.


    I am not seeing these APIs so I'm assuming you're using a different version of UIToolKit.

    Thanks for the reply, looking forward to figuring this one out.

    Thanks,
    Shade
     
  5. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    437
    Hi @__SHADE !

    These APIs were introduced in 2022.1, and unfortunately, they could not be backported. You can find more information on the TextField refactor in this post