- Fix code editor resize problems

- Fix crash when using `get` our `out` multiple times with the same variable name
- Show the name of the file in which the error occured
This commit is contained in:
Stone_Red
2022-01-13 07:30:37 +01:00
parent 719db0f74b
commit ea5bbda2c7
8 changed files with 76 additions and 29 deletions
+1 -1
View File
@@ -244,7 +244,7 @@ namespace YesNt.CodeEditor
private bool SizeChanged()
{
if (oldSize.X != Console.WindowWidth && oldSize.Y != Console.WindowHeight)
if (oldSize.X != Console.WindowWidth || oldSize.Y != Console.WindowHeight)
{
oldSize.X = Console.WindowWidth;
oldSize.Y = Console.WindowHeight;
+3 -3
View File
@@ -105,8 +105,8 @@ namespace YesNt.CodeEditor
string line = textEditor.Lines[textEditor.CursorPosition.Y + 1];
textEditor.Lines[textEditor.CursorPosition.Y] = line.Substring(0, Math.Min(textEditor.CursorPosition.X, line.Length));
textEditor.Lines[textEditor.CursorPosition.Y + 1] = line.Substring(Math.Min(textEditor.CursorPosition.X, line.Length));
textEditor.Lines[textEditor.CursorPosition.Y] = line[..Math.Min(textEditor.CursorPosition.X, line.Length)];
textEditor.Lines[textEditor.CursorPosition.Y + 1] = line[Math.Min(textEditor.CursorPosition.X, line.Length)..];
textEditor.CursorPosition.X = 0;
textEditor.CursorPosition.Y++;
@@ -167,7 +167,7 @@ namespace YesNt.CodeEditor
}
}
while (textEditor.Lines.Count > 0 && string.IsNullOrWhiteSpace(textEditor.Lines[textEditor.Lines.Count - 1]))
while (textEditor.Lines.Count > 0 && string.IsNullOrWhiteSpace(textEditor.Lines[^1]))
{
textEditor.Lines.RemoveAt(textEditor.Lines.Count - 1);
}
+10 -5
View File
@@ -10,7 +10,7 @@ namespace YesNt.CodeEditor
{
internal class SyntaxHighlighter
{
private ReadOnlyCollection<StatementInformation> statementInformation;
private readonly ReadOnlyCollection<StatementInformation> statementInformation;
public SyntaxHighlighter(ReadOnlyCollection<StatementInformation> statementInformation)
{
@@ -45,7 +45,7 @@ namespace YesNt.CodeEditor
{
continue;
}
input = AddColorInformation(input, input.Substring(0, name.Length), statement.Color, statement.SearchMode);
input = AddColorInformation(input, input[..name.Length], statement.Color, statement.SearchMode);
}
if (statement.SearchMode == SearchMode.Contains && $" {input} ".Contains(name))
{
@@ -69,7 +69,7 @@ namespace YesNt.CodeEditor
{
continue;
}
input = AddColorInformation(input, input.Substring(input.Length - name.Length), statement.Color, statement.SearchMode);
input = AddColorInformation(input, input[^name.Length..], statement.Color, statement.SearchMode);
}
if (statement.SearchMode == SearchMode.Exact && input.Equals(name))
{
@@ -103,6 +103,11 @@ namespace YesNt.CodeEditor
input = AddColorInformation(input, matches[i].Value, ConsoleColor.Blue, SearchMode.StartOfLine);
}
if (input.StartsWith('#'))
{
input = AddColorInformation(input, input, ConsoleColor.Gray, SearchMode.Exact);
}
foreach (string part in input.Split("\0"))
{
ConsoleColor consoleColor;
@@ -120,12 +125,12 @@ namespace YesNt.CodeEditor
consoleColor = ConsoleColor.White;
}
if (consoleColor == Console.BackgroundColor || consoleColor == ConsoleColor.DarkGray)
if (consoleColor == Console.BackgroundColor)
{
consoleColor = ConsoleColor.White;
}
Console.ForegroundColor = consoleColor;
Console.Write(messagePart, consoleColor);
Console.Write(messagePart);
Console.ForegroundColor = ConsoleColor.Gray;
}
}