Search Unity

Problems with Text Mesh Pro InputField selection

Discussion in 'UGUI & TextMesh Pro' started by patlenu, Feb 27, 2019.

  1. patlenu

    patlenu

    Joined:
    Jan 7, 2018
    Posts:
    8
    Hi!

    I have a text mesh pro inputfield in a Canvas that is in world space, and I have some troubles with the caret selection. Everytime I click it select's all of the characters instead of focusing once and then moving the caret's position , unlike the Unity inputfield component that works like this and has the beheavior I want but I want Text Mesh Pro's features. I tried to check/uncheck all the features (such as OnFocus - Select All) but it changes nothing.

    Another problem I have is when I click and the selection appears, sometimes the selection is offset from the text by around 1 character, but is fixed if you drag while clicking, which is a bit annoying visually,

    If anyone did have a similar problem and found a workaround it would be very helpful if you can share it, otherwise if the dev can point out if i'm missing something it would be great too,

    Thanks!
     

    Attached Files:

  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Make sure you did not alter the structure / hierarchy of the TMP Input Field. If you do not want Select All on Focus, make sure you unselect OnFocus - Select All.

    Are you able to reproduce the behavior in a new scene? If so can you provide the step to reproduce this?

    Also, check if you get the same behavior in the latest release of TMP for Unity 2018.3 which is version 1.4.0-preview.2a.
     
    sandolkakos likes this.
  3. patlenu

    patlenu

    Joined:
    Jan 7, 2018
    Posts:
    8
    Hi!

    Thank you for your quick answer, yes it happens in a new scene, and I always made sure I unchecked Select all, and I tested with the latest version of Text Mesh Pro 1.4.0-preview.2a. I have the same results.

    So I have here three pictures, the first one is when I focus sometimes the focus is offset for some reason (it seems to happen when I focus/defocus but it's not consistent), the second one is a new text mesh pro input field with OnFocus - Select All unchecked, and unless I click really slow it always selects all no matter what I do,

    And the last one is the "normal" Unity inputfield with the beheavior I want, which is just to select all one time and then move the caret,

    If you want I could produce small gifs so maybe it would be more clear visually,

    Thank you!
     

    Attached Files:

  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Can you provide me with the steps to reproduce this or a simple Repro scene / project?
     
  5. patlenu

    patlenu

    Joined:
    Jan 7, 2018
    Posts:
    8

    Attached Files:

  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Thank you for providing the Repro project.

    Regarding issue #1, it is the result of how you have the RectTransform of the child objects (Placeholder and Text) setup where their pivots do not align. To resolve this offset issue, make sure the size of the child text and placeholder are the same. Make sure their Left, Top, Right and Bottom are all zero. Make sure the Anchors min are 0, 0 and max 1, 1. This should result in these child objects being properly aligned (pivot and all) with the parent Text Area.

    upload_2019-3-1_15-6-52.png

    upload_2019-3-1_15-7-16.png

    The Placeholder and Text child objects also have their margins modified which I am not sure if that was set intentionally. So reset the margins on both these object to 0, 0, 0, 0.

    upload_2019-3-1_15-0-30.png

    When trying to resize the text object, the square dots modify the margins whereas dragging in the middle of lines alters the size of the RectTransform.



    In regards to issue #2, when OnFocus - Select All is enabled, I am getting the same behavior as the UI Input Field.



    When OnFocus - Select All is disabled, I am also getting the appropriate behavior which is to simply insert the caret. Note that a double click will result in the word being selected.

     
    Last edited: Mar 1, 2019
  7. patlenu

    patlenu

    Joined:
    Jan 7, 2018
    Posts:
    8
    Thank you for your answer!

    Maybe a step I forgot to say, but for the focusing problem, I have it when I try to click "kind of" fast, not enough to feel like i'm double clicking but just enough so I want to switch letter targeting, if I click as slow as on your gif it works perfectly,

    is there a way to disable the double click or detect it in a shorter lenght than right now?

    Thank you!
     
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Do you mean click kind of fast from one input field to another?
     
  9. patlenu

    patlenu

    Joined:
    Jan 7, 2018
    Posts:
    8
    No, in the same inputfield, to move the caret's position
     
  10. patlenu

    patlenu

    Joined:
    Jan 7, 2018
    Posts:
    8
    And I do feel like it could be a problem with the double click triggering "too fast" for my needs and auto-select the whole word, so if there is a way I could play with that it would be great!
     
  11. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Not sure why this delay would be too small in your case as no issues have been reported on this before. But for testing, change
    Code (csharp):
    1. private float m_DoubleClickDelay = 0.5f;
    in the TMP_InputField.cs file and let me know if a larger delay works better.
     
  12. patlenu

    patlenu

    Joined:
    Jan 7, 2018
    Posts:
    8
    I can't gain access to that file normally since it is private, is there any way I could change that property?
     
  13. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The package manager version of TMP includes source code so you should be able to edit that file. You should be able to navigate to that file in the "Packages/TextMesh Pro/Scripts/Runtime/..." folder.
     
  14. patlenu

    patlenu

    Joined:
    Jan 7, 2018
    Posts:
    8
    I changed the variable's value to 0.2f and it has the feel that I wanted now, thank you!
     
    Stephan_B likes this.
  15. drew55

    drew55

    Joined:
    Dec 13, 2017
    Posts:
    44
    @Stephan_B, you're a rockstar, thanks for all the good info in this thread!

    One thing I'm trying to figure out here is the best way for a double click to select all text (rather than stopping at a word delimiter like a space or period). Is there an easy way to do this?