Pasted /r/n aren't removed and break input fields

This is what happens when there’s copy/pasted \r\n at the end:

Fix in TMP_InputField::Append(string input):

for (int i = 0, imax = input.Length; i < imax; ++i)
{
    char c = input[i];

    if (c >= ' ' || c == '\t' || c == 10 || c == '\n'
        || (c == '\r' && (i + 1 == imax || input[i + 1] != '\n')))
    {
        Append(c);
    }
}

up

I am trying to reproduce the behavior you outlined above.

Are you copy / pasting just “\r\n”?

Are you inserting these before or after the “{”?

I’m copying the new line on windows “CR LF”. Better example:

https://www.youtube.com/watch?v=zHaAVI88eos

Insert (Ctrl + V) “CR LF” inside a word and then hit backspace. I guess what’s happening is that LF is removed but CR is still there breaking the input.

Instead of backspace you can try pressing left arrow, the first click will go back to previous line, next one will do nothing like it moved left of CR that’s treated as empty sign.

I guess better fix (mine just ignores CR when next char is LF) would be to remove CRLF together when using backspace or delete and jump over them when using arrows. #Edit Or not as there’s logic that converts single CRs to LFs when m_SoftKeyboard is used. Ignoring CRs and converting single ones to LF everywhere seems like simpler solution.

I could prevent from being appended to the text with the following simple change.

7396895--903443--upload_2021-8-7_0-41-0.png

However, this would not prevent a from existing in the text being set on the input field. As such, when using left or right arrow (just like in the Unity Editor) the caret would stop on those hidden control characters. Ie. stop on and . Same when using Backspace or Del.

There are TMP users using in text objects to create text overwrite FX but does this make sense in an Input Field? Is anyone actually using in an input field?

In Microsoft Word, Notepad++, etc. are distinct characters but are treated as a single character when using in the sense that Backspace or Del will remove both.

[quote=“Stephan_B, post:5, topic: 847937, username:Stephan_B”]
There are TMP users using in text objects to create text overwrite FX but does this make sense in an Input Field? Is anyone actually using in an input field?
[/quote]I guess not as overwrite FX makes no sense there.

Your fix sounds better and simper. c == 10 is the same as c == ‘\n’?

Yes.

I will actually address this differently as it is possible some users might be using .

The change I will make will continue to allow to be present in the text but just like MS Word or similar text editors treat as a single character, I will do so as well when using Backspace, Delete, Left and Right Arrow which these 2 characters will be treated as one when “Allow Rich Text Editing” is disabled.

1 Like

Seems like clicking at the end still breaks it, caret goes between \r and \n.

In this example I click on the end of a line (a bit next to the last letter) than delete to remove \n

This fixes it in OnPointerDown:

 if(insertionSide == CaretPosition.Right && m_TextComponent.textInfo.characterInfo[insertionIndex].character == '\r')
    insertionIndex--;

Please see if you get the same behavior with the latest preview release of the TMP package.

The latest preview for 2018.4 is version 1.6.0-preview.1, version 2.2.0-preview.1 for Unity 2019.4 and version 3.2.0-pre.1 for Unity 2020.x.

In Unity 2021.x, you may have to manually add the package by editing the manifest.json in the Packages folder due to package discovery restrictions.

Bug I described there is on pre.1.

Instead of deleting I can also start typing:

Can you provide me with a simple repro project for me to look at? If more convenient, you can submit a bug report with project or provide me with a zip of the project via PM (in case you don’t want to share).

If you go the submit bug way, please provide me with the Case # once you have it.

Sure, did both, zip is 20mb as there’s no library folder, Case 1362068 7gb.