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. Dismiss Notice

TextMesh Pro Control-i (^i) adding tab

Discussion in 'UGUI & TextMesh Pro' started by cardcastleusa, Mar 5, 2022.

  1. cardcastleusa

    cardcastleusa

    Joined:
    Mar 20, 2018
    Posts:
    9
    Having an issue with TextMeshPro InputField using the ASCII Character 9 (Horizontal Tab) when I'm setting up a shortcut for Italics.

    I'm building a simple text editor using rich text tags and universal hotkeys. Underline and Bold work just fine as the ASCII control functions are not inputted into the text box.

    Control-b (^b) - start of text
    Control-u (^u) - negative acknowledgement

    Is there a way to turn off Control-i (^i) from being inputted. The other way I was going to do this was to use a mediator that listened to the Input class and changed the text of the box from there.(Not Ideal)


    Issue(TMP)#1.PNG Issue(TMP)#2.PNG
     
  2. cardcastleusa

    cardcastleusa

    Joined:
    Mar 20, 2018
    Posts:
    9
    Figured it out, ended up using an additional TMP_InputValidator that was toggled when either control button was held. The override class used is as follows:

    Code (CSharp):
    1. [CreateAssetMenu(fileName = "New ControlValidator", menuName ="TMP_Validators/Control")]
    2.     public class TMP_ControlValidator : TMP_InputValidator
    3.     {
    4.         public override char Validate(ref string text, ref int pos, char ch)
    5.         {
    6.  
    7.             if (char.IsControl(ch))
    8.             {
    9.                 return '\0';
    10.             }
    11.  
    12.             pos++;
    13.             text += ch;
    14.             return ch;
    15.         }
    16.     }