Search Unity

Dsiable Tab in TextArea

Discussion in 'Scripting' started by pvloon, Aug 17, 2012.

  1. pvloon

    pvloon

    Joined:
    Oct 5, 2011
    Posts:
    591
    Hi,

    I've been reading about this a lot, but I can't seem to find any solution. I'm doing a quick editor extension, and the user needs to be able to make a tab in the textarea. However, unity cycles through all textfields with tab. I'm looking for a way to disable that. As far as I've read, you can't. This:

    Code (csharp):
    1.  
    2. if (Event.current.keyCode == KeyCode.Tab)
    3. {          
    4.      Event.current.Use();
    5. }
    6.  
    does catch the event, but doesn't prevent it. I can set back focus manually though. My idea was to insert a tab at the cursor position, but I can't seem to get that either. I'm using the following code:

    Code (csharp):
    1.  
    2.         GUI.SetNextControlName("TextArea");
    3.         string newValue = EditorGUILayout.TextArea(p.stringValue, GUILayout.MinHeight(50.0f));
    4.  
    5.         TextEditor editor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
    6.  
    7.         if (Event.current.keyCode == KeyCode.Tab)
    8.         {
    9.             GUI.FocusControl("TextArea");
    10.             newValue.Insert(editor.pos, "\t");
    11.             editor.SelectNone();
    12.  
    13.             Event.current.Use();
    14.         }
    15.  
    Editor.pos is always 0 though :(

    Any help would be greatly appreciated!
     
  2. pvloon

    pvloon

    Joined:
    Oct 5, 2011
    Posts:
    591
    Is this just not possible?
     
  3. pvloon

    pvloon

    Joined:
    Oct 5, 2011
    Posts:
    591
    I geuss that's a yes, to bad
     
  4. vedram

    vedram

    Joined:
    May 23, 2018
    Posts:
    5
    KaiClavier likes this.
  5. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Thanks for registering a new account to necropost a 6 year old post and answer a question that's relevant only to obsolete versions of Unity UI's. /s
     
    vedram, SparrowGS and Antypodish like this.
  6. vedram

    vedram

    Joined:
    May 23, 2018
    Posts:
    5
    Always a pleasure!
    Thank you for your post, it is really a quality one and brings lot of value to all of us.

    And actually, I posted it because I had problems with capturing tab in Unity 2018.3.... It was relevant to me, and could be relevant to somebody else (not you, obviously).
     
  7. vedram

    vedram

    Joined:
    May 23, 2018
    Posts:
    5
    And thanks for warm welcome to community!
     
    victorafael_com, t2g4 and MatejR24 like this.