diff --git a/src/UI/CSConsole/CSAutoCompleter.cs b/src/UI/CSConsole/CSAutoCompleter.cs index 697a185..b81394a 100644 --- a/src/UI/CSConsole/CSAutoCompleter.cs +++ b/src/UI/CSConsole/CSAutoCompleter.cs @@ -41,7 +41,7 @@ namespace UnityExplorer.UI.CSConsole suggestions.Clear(); int caret = Math.Max(0, Math.Min(InputField.Text.Length - 1, InputField.Component.caretPosition - 1)); - int start = caret; + int startIdx = caret; // If the character at the caret index is whitespace or delimiter, // or if the next character (if it exists) is not whitespace, @@ -55,17 +55,20 @@ namespace UnityExplorer.UI.CSConsole } // get the current composition string (from caret back to last delimiter) - while (start > 0) + while (startIdx > 0) { - start--; - char c = InputField.Text[start]; + startIdx--; + char c = InputField.Text[startIdx]; if (delimiters.Contains(c)) { - start++; + startIdx++; + while (char.IsWhiteSpace(InputField.Text[startIdx])) + startIdx++; break; } } - string input = InputField.Text.Substring(start, caret - start + 1); + string input = InputField.Text.Substring(startIdx, caret - startIdx + 1); + // Get MCS completions diff --git a/src/UI/CSConsole/Lexers/KeywordLexer.cs b/src/UI/CSConsole/Lexers/KeywordLexer.cs index 376c793..10f8892 100644 --- a/src/UI/CSConsole/Lexers/KeywordLexer.cs +++ b/src/UI/CSConsole/Lexers/KeywordLexer.cs @@ -41,6 +41,10 @@ namespace UnityExplorer.UI.CSConsole.Lexers while (!lexer.EndOfInput && char.IsLetter(lexer.PeekNext())) sb.Append(lexer.Current); + // next must be whitespace or delimiter + if (!lexer.EndOfInput && !(char.IsWhiteSpace(lexer.Current) || lexer.IsDelimiter(lexer.Current))) + return false; + if (keywords.Contains(sb.ToString())) { if (!lexer.EndOfInput) diff --git a/src/UI/CSConsole/Lexers/SymbolLexer.cs b/src/UI/CSConsole/Lexers/SymbolLexer.cs index 2562d0a..4d35297 100644 --- a/src/UI/CSConsole/Lexers/SymbolLexer.cs +++ b/src/UI/CSConsole/Lexers/SymbolLexer.cs @@ -11,7 +11,7 @@ namespace UnityExplorer.UI.CSConsole.Lexers protected override Color HighlightColor => new Color(0.6f, 0.6f, 0.6f); // all symbols are delimiters - public override IEnumerable Delimiters => symbols; + public override IEnumerable Delimiters => symbols.Where(it => it != '.'); // '.' is not a delimiter, only a separator. public static bool IsSymbol(char c) => symbols.Contains(c);