Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Mar 26, 2013 at 08:43 AM by Jake-L for the following reason:

Found the reason

avatar image
3
Question by Jake-L · Mar 25, 2013 at 10:38 AM · editoreventtextarea

Adding Tab support to TextArea's TextEditor (almost done)

Hi,

I want my TextArea to support entering tabs. After a lot of search I finally came up with this:

 Event ev = Event.current;
 string mPlaintext = GUILayout.TextArea(myText, GUILayout.ExpandHeight(true));
 TextEditor mEditor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
                 
 if (GUIUtility.keyboardControl==mEditor.controlID &&  ev.Equals(Event.KeyboardEvent("tab"))) {
    if (mPlaintext.Length > mEditor.pos) {
       mPlaintext = mPlaintext.Insert(mEditor.pos, "\t");
       mEditor.pos++;
       mEditor.selectPos = mEditor.pos;
       }
    ev.Use();
 }
                 
 myText = mPlaintext;

While this works (\\t is added to the text in the TextArea), ev.Use() seems to be ignored, so the default behaviour of tab kicks in and the next control is selected.

Anybody knows how I can eat the tab event to prevent control switching?

Edit: Seems to be a problem with GUILayout.TextArea. Using GUI.TextArea does the trick!

Thanks Jake

PS: Don't know if it matters, but the code is placed in EditorWindow.OnGUI()

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

  • Sort: 
avatar image
0

Answer by Benproductions1 · Mar 26, 2013 at 01:11 AM

Hi! there,

What you probably want to do is force focus on the TextField. You can do this by using the following commands:

 //Before you call the text field, give it a special identifier
 GUI.SetNextControlName("1");
 
 //You can then call the following to force focus on the text field with that identifier
 GUI.FocusControl("1");

I have found this useful more often than not. If you have multiple text fields, you can keep track of them yourself, and only change the focus, when other exit events happen :)

Hope this helps, Benproductions1

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Unitraxx · Mar 26, 2013 at 01:17 AM 0
Share

What if there are 2 textfields next to each other, both having assigned such an ID. If you are focussing one, while the other gets clicked, how does changing focus work then with your method? You probably have to control if the other textArea gets clicked now?

avatar image
0

Answer by Jake-L · Mar 26, 2013 at 08:41 AM

GUI.FocusControl() doesn't help, but I figured out that using GUI.TextArea instead of GUILayout.TextArea works. Thanks anyway!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UnityEvent draws debug variables in the inspector 0 Answers

The type or namespace name 'EventSystems' does not exist in the namespace 'UnityEngine' 0 Answers

Mouse click in edit mode. ✱✺✸❁ 1 Answer

Detect Enter Key Event with GUILayout.TextField Focused 1 Answer

Detect mouse up or end of drag on any scene object 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges