Search Unity

TextMesh Pro Custom InputValidators have unpleasant behavior with text selections

Discussion in 'UGUI & TextMesh Pro' started by cxode, Feb 12, 2022.

  1. cxode

    cxode

    Joined:
    Jun 7, 2017
    Posts:
    268
    Currently,
    TMP_InputValidator
    only handles the caret position of the InputField, not the selection position. This presents a problem when the user selects some text in a custom-validated inputfield and then starts typing. To handle this case, the inputfield will delete anything in the selection. (line 4039 of
    TMP_InputField.cs
    )

    This works as expected when the validator approves the typed character: the selected text is deleted and replaced by the typed character. However, when the validator denies the typed character, the selected text is still deleted. This is unexpected behavior: if the new character is denied, the text and selection should not change. Compare the behavior in this situation with a custom validator to any of the built-in validators.

    My proposal is that TMP should check if the validator returns
    '\0'
    , and if so, don't modify the selection position or delete any text.

    This may seem like a minor detail, but I have an important inputfield in my game with a custom validator and I notice this issue often while testing. It's pretty annoying.