Search Unity

Text Mesh Pro style RTF tag obfuscating input position of TMP_InputField

Discussion in 'UGUI & TextMesh Pro' started by aciusa, Jun 7, 2019.

  1. aciusa

    aciusa

    Joined:
    Apr 19, 2016
    Posts:
    9
    I've been working on a project that requires the content of input fields to be modified by a style tag. The tag works beautifully until you need to actually edit the text in the input field. The input appears to be offset by an amount equal to the first tag in a compound style tag, and this offset is increased by a uniform amount equal to n * firstTag.Length where n is the number of previous compound style tags in the Input Field.

    I created an extended version of the TMP_InputField class in order to debug several of the internal values, such as caret position and selection string anchor position. While the caret position is 0 the selection string position is 12 (the length of the first element in the compound tag), but the style tags full length is 25. The selection string position would be expected to be either 0 or 25, but the style tag appears to just be obfuscating the actual tags in a lower level version of the Input Field contents. This 12 offset from caret position 0 continues for each increment of the caret position, so that caret position 2 is actually selection string position 14, not position 27. This causes any input placed at the beginning of the input field to be typed inside of the style tag, breaking it.

    To solve my problem, I am wondering if it is possible to access that lower level of the input field contents to modify the string selection position by a calculated style tag offset. Such a solution would allow my existing systems to operate with minimal modification.

    This style tag is used in other text fields throughout the project, so it would be nice to continue to use it, as it gives my software an easy template for generating the aesthetic framework for the text fields. I understand if access to this lower level object is restricted to maintain data integrity however.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    What version of the TMP package are you using?

    Can you provide me with a simple Repro project / scene to look at this?
     
  3. aciusa

    aciusa

    Joined:
    Apr 19, 2016
    Posts:
    9
    I'll put something together and contact you in an hour or two
     
  4. aciusa

    aciusa

    Joined:
    Apr 19, 2016
    Posts:
    9
    I'm using TMP version 1.2.4 (current version) with Unity 2017.4, and have replicated it in 2018.2 (which is the package that I've attached since 2018 produces smaller package files). Simply click somewhere in the center of the text field and start typing and the problem will become evident immediately. Additionally if you strip the input field of all text except the tag through the inspector and click the text will also be offset when you attempt to edit any text typed. In my production version I have a script that prevents you from typing inside of tags but I have not attached that to this iteration of the project as it does not seem to have any effect in regards to the style tag bug.

    If you read the input values, you will see that the position of the last tag while typing is 22, the length of the style tag, but the selection string position at the start of the input field is 32, the length of the composite tag, causing a 10 character offset when typing. So my previous calculation was slightly off due to coincidence, it should be offset = n * (compound(style(n)).length - style(n).length) where n is the number of previous style tags.

    edit - had flipped the style and composite tag values from the debug log
     

    Attached Files:

    Last edited: Jun 10, 2019