From 06122fe8c9e21b2afd6ab40f65647e9a48cca1f3 Mon Sep 17 00:00:00 2001 From: Sinai Date: Sun, 9 May 2021 20:32:47 +1000 Subject: [PATCH] Update CSLexer.cs --- src/UI/CSConsole/CSLexer.cs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/UI/CSConsole/CSLexer.cs b/src/UI/CSConsole/CSLexer.cs index 0555d8f..0d060f1 100644 --- a/src/UI/CSConsole/CSLexer.cs +++ b/src/UI/CSConsole/CSLexer.cs @@ -270,6 +270,9 @@ namespace UnityExplorer.UI.CSharpConsole } else { + if (c == indentClose) + currentIndent--; + if (prevWasNewLine && curLineIndent < currentIndent) { ExplorerCore.Log("line is not indented enough"); @@ -281,28 +284,25 @@ namespace UnityExplorer.UI.CSharpConsole } // check for brackets - if (c == indentClose || c == indentOpen) + if ((c == indentClose || c == indentOpen) && !prevWasNewLine) { - ExplorerCore.Log("char is a bracket"); + ExplorerCore.Log("bracket needs new line"); - if (c == indentOpen) - currentIndent++; - else if (c == indentClose) - currentIndent--; - - if (!prevWasNewLine) - { - ExplorerCore.Log("it wasnt on a new line, doing so..."); - // need to put it on a new line - sb.Insert(i, $"\n{new string('\t', currentIndent - 1)}"); - caretPos += 1 + currentIndent; - i += 1 + currentIndent; - } + // need to put it on a new line + sb.Insert(i, $"\n{new string('\t', currentIndent)}"); + caretPos += 1 + currentIndent; + i += 1 + currentIndent; } + if (c == indentOpen) + currentIndent++; + prevWasNewLine = false; } } + + // todo put caret on new line after previous bracket if needed + // indent caret to current indent // process after caret position, make sure there are equal opened/closed brackets ExplorerCore.Log("-- after caret --"); @@ -331,6 +331,7 @@ namespace UnityExplorer.UI.CSharpConsole ExplorerCore.Log("there are not enough closing brackets, curIndent is " + currentIndent); // There are not enough close brackets + // TODO this should append in reverse indent order (small indents inserted first, then biggest). while (currentIndent > 0) { ExplorerCore.Log("Inserting closing bracket with " + currentIndent + " indent");