Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit aaab10a

Browse files
committed
Do auto-indent before highlighting so the characters are in the correct position
1 parent d7008db commit aaab10a

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/UI/CSConsole/ConsoleController.cs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using UnityExplorer.UI.Panels;
1313
using UnityExplorer.UI.Widgets.AutoComplete;
1414
using System.Reflection;
15+
using Mono.CSharp;
1516

1617
namespace UnityExplorer.UI.CSConsole
1718
{
@@ -150,15 +151,16 @@ public static void Evaluate(string input, bool supressLog = false)
150151

151152
try
152153
{
153-
// Try to "Compile" the code (tries to interpret it as REPL)
154-
var evaluation = Evaluator.Compile(input);
155-
if (evaluation != null)
154+
// Compile the code. If it returned a CompiledMethod, it is REPL.
155+
CompiledMethod repl = Evaluator.Compile(input);
156+
157+
if (repl != null)
156158
{
157159
// Valid REPL, we have a delegate to the evaluation.
158160
try
159161
{
160162
object ret = null;
161-
evaluation.Invoke(ref ret);
163+
repl.Invoke(ref ret);
162164
var result = ret?.ToString();
163165
if (!string.IsNullOrEmpty(result))
164166
ExplorerCore.Log($"Invoked REPL, result: {ret}");
@@ -172,9 +174,7 @@ public static void Evaluate(string input, bool supressLog = false)
172174
}
173175
else
174176
{
175-
// The input was not recognized as an evaluation. Compile the code.
176-
177-
Evaluator.Run(input);
177+
// The compiled code was not REPL, so it was a using directive or it defined classes.
178178

179179
string output = ScriptEvaluator._textWriter.ToString();
180180
var outputSplit = output.Split('\n');
@@ -233,6 +233,12 @@ private static void OnInputChanged(string value)
233233
if (EnableSuggestions && AutoCompleteModal.CheckEnter(Completer))
234234
OnAutocompleteEnter();
235235

236+
if (!settingCaretCoroutine)
237+
{
238+
if (EnableAutoIndent)
239+
DoAutoIndent();
240+
}
241+
236242
var inStringOrComment = HighlightVisibleInput();
237243

238244
if (!settingCaretCoroutine)
@@ -244,9 +250,6 @@ private static void OnInputChanged(string value)
244250
else
245251
Completer.CheckAutocompletes();
246252
}
247-
248-
if (EnableAutoIndent)
249-
DoAutoIndent();
250253
}
251254

252255
UpdateCaret(out _);
@@ -261,16 +264,16 @@ public static void Update()
261264

262265
UpdateCaret(out bool caretMoved);
263266

264-
if (!settingCaretCoroutine && EnableSuggestions && AutoCompleteModal.CheckEscape(Completer))
267+
if (!settingCaretCoroutine && EnableSuggestions)
265268
{
266-
OnAutocompleteEscaped();
267-
return;
268-
}
269+
if (AutoCompleteModal.CheckEscape(Completer))
270+
{
271+
OnAutocompleteEscaped();
272+
return;
273+
}
269274

270-
if (!settingCaretCoroutine && EnableSuggestions && caretMoved)
271-
{
272-
AutoCompleteModal.Instance.ReleaseOwnership(Completer);
273-
//Completer.CheckAutocompletes();
275+
if (caretMoved)
276+
AutoCompleteModal.Instance.ReleaseOwnership(Completer);
274277
}
275278

276279
if (EnableCtrlRShortcut

0 commit comments

Comments
 (0)