[Refactor] Invert if to reduce nesting.

This commit is contained in:
2025-11-24 19:19:14 +00:00
parent dea49e235d
commit 7b487033b5
16 changed files with 126 additions and 163 deletions

View File

@@ -485,17 +485,14 @@ public partial class SpectreTextBlock : TextBlock
{
i++;
if(i < text.Length && text[i] == ']')
{
// Found [/], close the most recent tag
if(tagStack.Count > 0)
{
(int openStart, int openTagEnd, string tag) = tagStack.Pop();
int closeTagEnd = i + 1; // After the ']' of [/]
result.Add(new MarkupTag(openStart, closeTagEnd, tag, openTagEnd, tagStart));
}
if(i >= text.Length || text[i] != ']') continue;
i++;
// Found [/], close the most recent tag
if(tagStack.Count > 0)
{
(int openStart, int openTagEnd, string tag) = tagStack.Pop();
int closeTagEnd = i + 1; // After the ']' of [/]
result.Add(new MarkupTag(openStart, closeTagEnd, tag, openTagEnd, tagStart));
}
}
else
@@ -513,12 +510,10 @@ public partial class SpectreTextBlock : TextBlock
int openTagEnd = i + 1; // After the ']'
tagStack.Push((tagStart, openTagEnd, tagName));
}
i++;
}
}
else
i++;
i++;
}
return result;

View File

@@ -40,14 +40,11 @@ public partial class FileView : UserControl
private void ListBox_OnKeyDown(object sender, KeyEventArgs e)
{
if(e.Key == Key.Enter)
{
if(DataContext is FileViewViewModel vm && vm.OpenSelectedFileCommand.CanExecute(null))
{
vm.OpenSelectedFileCommand.Execute(null);
e.Handled = true;
}
}
if(e.Key != Key.Enter) return;
if(DataContext is not FileViewViewModel vm || !vm.OpenSelectedFileCommand.CanExecute(null)) return;
vm.OpenSelectedFileCommand.Execute(null);
e.Handled = true;
}
/// <inheritdoc />