Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

TextMesh Pro Input field selection disappear when another UI item is activated

Discussion in 'UGUI & TextMesh Pro' started by Gladyon, Jul 22, 2021.

  1. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    322
    Is it possible to keep the TMP input field selection visible when using another UI item (clicking on a button for example)?

    What I want to do is:
    - display some text in a read-only input field
    - let the user select part of that text
    - right-click on another input field (not read-only) to display a context menu
    - use the context menu to insert a copy of the selection from the read-only input field

    Under the hood the selection is kept, so the feature actually works fine, but it's a bit confusing to the user that the selection disappear when the context menu is displayed.
     
  2. astorms

    astorms

    Joined:
    Jan 31, 2018
    Posts:
    45
    I have a need for the same feature. Maybe a simple property called keepTextSelectionVisible that when set to true forces the text selection to be visible regardless of selection state, and when set to false it reverts to the current behavior?
     
    Last edited: Aug 6, 2021
  3. astorms

    astorms

    Joined:
    Jan 31, 2018
    Posts:
    45
    @Stephan_B do you have any guidance on how we might go about achieving such functionality?
     
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,067
    I'll take a closer look next week to see if I can add a new option for this.
     
  5. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,067
    I added the requested functionality and new property which is "keepTextSelectionVisible" as seen below.

    upload_2021-8-7_15-23-58.png

    When "Reset On Deactivation" is true, the text selection is always released.

    Double clicking in the Game View (ie. in empty space and not another UI Element) will always release the selection and input field.
     
    astorms likes this.
  6. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    322
    Thank you, it will help.
     
  7. astorms

    astorms

    Joined:
    Jan 31, 2018
    Posts:
    45
    Thanks so much! This will be a huge help for us. Will this be included in the 3.2.0 release?
     
  8. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,067
    Yes. It is included in 3.2.0-pre.1 for Unity 2020.x or newer which was published last night.
     
  9. astorms

    astorms

    Joined:
    Jan 31, 2018
    Posts:
    45
    Great, thanks so much. The keepTextSelectionVisible works almost exactly as we need it to. In our use case, we will be toggling the ResetOnDeactivation/keepTextSelectionVisible at runtime to achieve the behavior we are looking for. For example we'll need to do something like the following:
    1. Set ResetOnDeactivation to true and keepTextSelectionVisible to false for the default state of all input fields
    2. If the user starts dragging in an input field to select text and during the drag moves the mouse over another input field to select the text in that input field too, we will set ResetOnDeactivation to false and keepTextSelectionVisible to true on the first input field.
    3. As soon as the user clicks anywhere, either inside of an input field or elsewhere, we will set keepTextSelectionVisible to false and ResetOnDeactivation to true on all input fields.
    4. Lastly, we will need to reset all of the input fields so that they clear their selection and are no longer activated.
    Step 4 is the one that we are unsure how to achieve. Currently, setting ResetOnDeactivation back to true doesn't immediately reset and clear the selection of the input field - it won't reset or clear until the user has clicked back into it and then clicked away from it. So the question is: is there a method we can call or property we can set to programatically return an input field to its deactivated/unfocused state and clear its text?


    Here is a a video of the effect we are trying to achieve. Each column would be a TMP input field:
     
    Last edited: Aug 12, 2021
unityunity