Permalink
Browse files

Updating this to work properly in a few more cases.

Only tested with 3.5.2...
  • Loading branch information...
1 parent 5662b52 commit c6b08b017a60fed538d3502bd354cd9f762be658 @MrJoy committed May 20, 2012
Showing with 11 additions and 7 deletions.
  1. +11 −7 AutoSelect.cs
View
@@ -65,7 +65,7 @@ public static class GUILayoutAutoSelect {
// Helper/support stuff.
public static class CoreAutoSelect {
// Internal gubbins for auto-select controls.
- private static int lastKeyboardControl = -1;
+ public static string lastFocusedControl = null;
public static void Pre(string name) {
// Each widget needs a unique name so we can differentiate them.
GUI.SetNextControlName(name);
@@ -74,17 +74,21 @@ public static class CoreAutoSelect {
public static void Post(string name) {
// And now, the magic:
// Check to see if keyboard focus has changed on us...
- int kbdCtrlId = GUIUtility.keyboardControl;
- if(kbdCtrlId != lastKeyboardControl) {
+ string focusedControl = GUI.GetNameOfFocusedControl();
+ if(lastFocusedControl != focusedControl) {
// It has! Now, check to see if the focused control is this text area...
- string focusedControl = GUI.GetNameOfFocusedControl();
if(focusedControl == name) {
// It is! Now, get the editor state (spooky voodo!), and tweak it.
- TextEditor t = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), kbdCtrlId);
+ TextEditor t = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
t.SelectAll();
+
// Update this here or state gets mangled when there's multiple
- // AutoSelectTextArea.
- lastKeyboardControl = kbdCtrlId;
+ // AutoSelectTextArea objects and you switch between them.
+ lastFocusedControl = focusedControl;
+ } else if(focusedControl == "") {
+ // Update this here or switching back and forth between normal TextArea
+ // and AutoSelectTextArea widgets will have problems.
+ lastFocusedControl = focusedControl;
}
}
}

0 comments on commit c6b08b0

Please sign in to comment.