Update CSLexer.cs

This commit is contained in:
Sinai 2021-05-09 20:32:47 +10:00
parent e6b253fed9
commit 06122fe8c9

View File

@ -270,6 +270,9 @@ namespace UnityExplorer.UI.CSharpConsole
} }
else else
{ {
if (c == indentClose)
currentIndent--;
if (prevWasNewLine && curLineIndent < currentIndent) if (prevWasNewLine && curLineIndent < currentIndent)
{ {
ExplorerCore.Log("line is not indented enough"); ExplorerCore.Log("line is not indented enough");
@ -281,28 +284,25 @@ namespace UnityExplorer.UI.CSharpConsole
} }
// check for brackets // 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) // need to put it on a new line
currentIndent++; sb.Insert(i, $"\n{new string('\t', currentIndent)}");
else if (c == indentClose) caretPos += 1 + currentIndent;
currentIndent--; i += 1 + 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;
}
} }
if (c == indentOpen)
currentIndent++;
prevWasNewLine = false; 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 // process after caret position, make sure there are equal opened/closed brackets
ExplorerCore.Log("-- after caret --"); ExplorerCore.Log("-- after caret --");
@ -331,6 +331,7 @@ namespace UnityExplorer.UI.CSharpConsole
ExplorerCore.Log("there are not enough closing brackets, curIndent is " + currentIndent); ExplorerCore.Log("there are not enough closing brackets, curIndent is " + currentIndent);
// There are not enough close brackets // There are not enough close brackets
// TODO this should append in reverse indent order (small indents inserted first, then biggest).
while (currentIndent > 0) while (currentIndent > 0)
{ {
ExplorerCore.Log("Inserting closing bracket with " + currentIndent + " indent"); ExplorerCore.Log("Inserting closing bracket with " + currentIndent + " indent");