Skip to content

Commit 0a51e92

Browse files
authored
Merge pull request #11 from wolfreak99/refactor_2
More refactoring
2 parents aecf116 + 9f2f4bd commit 0a51e92

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

Assets/UnityShell/Editor/Scripts/AutocompleteBox.cs

+16-14
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void OnGUI(string result, Rect rect)
7878
}
7979
searchString = result;
8080

81-
DoResults(rect);
81+
DrawResults(rect);
8282
}
8383

8484
public void HandleEvents()
@@ -92,24 +92,26 @@ public void HandleEvents()
9292

9393
if (current.type == EventType.KeyDown)
9494
{
95-
if (current.keyCode == KeyCode.Escape)
95+
switch (current.keyCode)
9696
{
97+
case KeyCode.Escape:
9798
showResults = false;
98-
}
99-
if (current.keyCode == KeyCode.UpArrow)
100-
{
99+
break;
100+
case KeyCode.UpArrow:
101101
current.Use();
102102
selectedIndex--;
103-
}
104-
else if (current.keyCode == KeyCode.DownArrow)
105-
{
103+
break;
104+
case KeyCode.DownArrow:
106105
current.Use();
107106
selectedIndex++;
108-
}
109-
else if (current.keyCode == KeyCode.Return && selectedIndex >= 0)
110-
{
111-
current.Use();
112-
OnConfirm(results[selectedIndex]);
107+
break;
108+
case KeyCode.Return:
109+
if (selectedIndex >= 0)
110+
{
111+
current.Use();
112+
OnConfirm(results[selectedIndex]);
113+
}
114+
break;
113115
}
114116

115117
if (selectedIndex >= results.Length)
@@ -123,7 +125,7 @@ public void HandleEvents()
123125
}
124126
}
125127

126-
private void DoResults(Rect drawRect)
128+
private void DrawResults(Rect drawRect)
127129
{
128130
if (results.Length <= 0 || !showResults)
129131
{

Assets/UnityShell/Editor/Scripts/UnityShellEditorWindow.cs

+15-15
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,18 @@ private string text
8888

8989
[SerializeField]
9090
private List<string> inputHistory = new List<string>();
91-
92-
private bool requestMoveToCursorToEnd;
91+
private int positionInHistory;
92+
93+
private bool requestMoveCursorToEnd;
9394
private bool requestFocusOnTextArea;
94-
9595
private bool requestRevertNewLine;
9696

9797
private string input = "";
9898
private string lastWord = "";
99+
private string savedInput;
99100

100101
private Vector2 lastCursorPos;
101102

102-
private int positionInHistory;
103-
104-
private string savedInput;
105-
106103
private void Awake()
107104
{
108105
ClearText();
@@ -142,14 +139,14 @@ private void OnInspectorUpdate()
142139

143140
private void OnGUI()
144141
{
145-
textEditor = (TextEditor) GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
142+
textEditor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
146143
if (text == "")
147144
{
148145
AppendStartCommand();
149146
ScheduleMoveCursorToEnd();
150147
}
151148

152-
EnsureNotAboutToTypeAtInvalidPosition();
149+
HandleInvalidTypePositions();
153150
autocompleteBox.HandleEvents();
154151
HandleHistory();
155152
DoAutoComplete();
@@ -240,10 +237,10 @@ private string GetInput()
240237
private void HandleRequests()
241238
{
242239
var current = Event.current;
243-
if (requestMoveToCursorToEnd && current.type == EventType.Repaint)
240+
if (requestMoveCursorToEnd && current.type == EventType.Repaint)
244241
{
245242
textEditor.MoveTextEnd();
246-
requestMoveToCursorToEnd = false;
243+
requestMoveCursorToEnd = false;
247244
Repaint();
248245
}
249246
else if (focusedWindow == this && requestFocusOnTextArea)
@@ -266,7 +263,10 @@ private void HandleRequests()
266263
lastCursorPos = cursorPos;
267264
}
268265

269-
private void EnsureNotAboutToTypeAtInvalidPosition()
266+
/// <summary>
267+
/// Ensures not about to type at an invalid position.
268+
/// </summary>
269+
private void HandleInvalidTypePositions()
270270
{
271271
var current = Event.current;
272272

@@ -278,7 +278,6 @@ private void EnsureNotAboutToTypeAtInvalidPosition()
278278
if (current.keyCode == KeyCode.Backspace)
279279
{
280280
cursorIndex--;
281-
282281
}
283282

284283
if (cursorIndex < lastIndexCommand)
@@ -310,6 +309,7 @@ private void DrawAll()
310309
EditorGUILayout.EndScrollView();
311310

312311
autocompleteBox.results = shellEvaluator.completions;
312+
313313
var pos = textEditor.graphicalCursorPos;
314314
var rect = new Rect(pos.x, pos.y, 300, 200);
315315
rect.y += 34;
@@ -341,6 +341,7 @@ private void DrawConsole()
341341
}
342342

343343
AppendStartCommand();
344+
ScheduleMoveCursorToEnd();
344345

345346
current.Use();
346347
}
@@ -358,12 +359,11 @@ private void ScrollDown()
358359
private void AppendStartCommand()
359360
{
360361
text += CommandName;
361-
ScheduleMoveCursorToEnd();
362362
}
363363

364364
private void ScheduleMoveCursorToEnd()
365365
{
366-
requestMoveToCursorToEnd = true;
366+
requestMoveCursorToEnd = true;
367367
ScrollDown();
368368
}
369369

0 commit comments

Comments
 (0)