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:
Create an input field. Turn off ALL Control Settings, except turn on Rich Text.
Manually set the inputField.text = ’ <link=“test”>test'. Don’t enter the single quotes, that just shows where the string starts and ends. Very important to include the leading space here.
Enter play mode, select all text in the input field, and delete. You should be left with , which only appears in the inspector.
This also occurs when I have multiple links in a row (e.g., <link=“test”>test <link=“test”>test) and I drag the second ‘test’ up to right after the last character of the first test. The trailing 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.
I tried the above text with " <link=“test”>test" 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.
@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.
Anchor inside tag, Focus not inside tag, move right to left
Anchor not inside tag, Focus inside tag, move left to right
Anchor inside tag, Focus not inside tag, move left to right
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.