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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

TextMesh Pro Rich Text Tags partially removed on certain user deletions in TMPro Input Fields.

Discussion in 'UGUI & TextMesh Pro' started by brandonholt95, Sep 19, 2021.

  1. brandonholt95

    brandonholt95

    Joined:
    Feb 12, 2020
    Posts:
    14
    Hi there!

    I'm having an issue where on certain types of text deletions in an input field, only one side of the rich text tag is removed. This is hugely problematic and I can't wrap my head around why this behavior would ever be desired.

    Here's how to recreate the issue:

    1) Create an input field. Turn off ALL Control Settings, except turn on Rich Text.
    2) Manually set the inputField.text = ' <link="test">test</link>'. Don't enter the single quotes, that just shows where the string starts and ends. Very important to include the leading space here.
    3) Enter play mode, select all text in the input field, and delete. You should be left with </link>, which only appears in the inspector.

    This also occurs when I have multiple links in a row (e.g., <link="test">test</link> <link="test">test</link>) and I drag the second 'test' up to right after the last character of the first test. The trailing </link> is left behind upon deletion.

    Note, this never happens during any other type of deletion event, such as when you drag into the middle of another word, or even just one word itself. Only when you drag one or more words PLUS one extra space character. This is super annoying and I'm not sure if I'm doing something wrong or if this is the desired behavior but I could really use some help fixing this.

    My only idea so far is to check for uneven <link= vs. </l events and delete unnecessary ones every time input is updated, but this would put undue strain on performance.

    Any help is appreciated! @Stephan_B
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    I tried the above text with " <link="test">test</link>" and used CTRL-A to select all. Then I used either DEL or BACKSPACE and all of the text was deleted.

    I am using the latest preview release of the TMP package which is version 1.6.0-preview.1 for 2018.4, version 2.2.0-preview.1 for Unity 2019.4 and version 3.2.0-pre.1 for Unity 2020.x or newer.
     
  3. brandonholt95

    brandonholt95

    Joined:
    Feb 12, 2020
    Posts:
    14
    @Stephan_B Thanks for looking into this, but I need to clarify the steps. You are correct that selecting all text with CTRL + A will correctly delete all the tags, but that is not the issue I am noticing. I did some more digging, and it turns out there are actually four scenarios where this will happen, which is a function of whether or not the anchor position and focus position of the drag are within a rich text tag.

    1) Anchor inside tag, Focus not inside tag, move right to left
    2) Anchor not inside tag, Focus inside tag, move left to right
    3) Anchor inside tag, Focus not inside tag, move left to right
    4) Anchor not inside tag, Focus inside tag, move right to left.

    I've shown each of these examples in this video here:


    I go through each example, then at the very end I show that as you noticed, CTRL + A selects everything of course, but that's not the issue here. I am also using version 2.2.0-preview.1 for Unity 2019.4, as you see in the video.

    I can also include a small repro project if you'd like, but the video should be enough to show you the issue.

    Thanks in advance!
    Brandon