Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions PSReadLine/Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void MaybeEmphasize(int i, string currColor)
// use the tokens color otherwise use the initial color.
var state = tokenStack.Peek();
var token = state.Tokens[state.Index];
if (i == token.Extent.EndOffset)
while (i == token.Extent.EndOffset)
{
if (token == state.Tokens[state.Tokens.Length - 1])
{
Expand Down Expand Up @@ -630,6 +630,11 @@ private static int LengthInBufferCells(char c)

private string GetTokenColor(Token token)
{
if ((token.TokenFlags & TokenFlags.CommandName) != 0)
{
return _options._commandColor;
}

switch (token.Kind)
{
case TokenKind.Comment:
Expand All @@ -653,11 +658,6 @@ private string GetTokenColor(Token token)
return _options._numberColor;
}

if ((token.TokenFlags & TokenFlags.CommandName) != 0)
{
return _options._commandColor;
}

if ((token.TokenFlags & TokenFlags.Keyword) != 0)
{
return _options._keywordColor;
Expand Down
33 changes: 33 additions & 0 deletions test/RenderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,39 @@ public void Render()
InputAcceptedNow
));

// This tests for priority to highlight a command regardless of token kind and nested tokens potential to bleed the parent token color to the next token
Test("", Keys(
". -abc def;. abc$name -def",
_.Home,
CheckThat(() =>
AssertScreenIs(1,
TokenClassification.None, ". ",
TokenClassification.Command, "-abc",
TokenClassification.None, " def;. ",
TokenClassification.Command, "abc",
TokenClassification.Variable, "$name",
TokenClassification.None, " ",
TokenClassification.Parameter, "-def")),
_.Ctrl_c,
InputAcceptedNow
));

// Additional test for priority to highlight a command regardless of token kind and nested tokens potential to bleed the parent token color to the next token
Test("", Keys(
". ++ abc$name -def",
_.Home,
CheckThat(() =>
AssertScreenIs(1,
TokenClassification.None, ". ",
TokenClassification.Command, "++",
TokenClassification.None, " abc",
TokenClassification.Variable, "$name",
TokenClassification.None, " ",
TokenClassification.Parameter, "-def")),
_.Ctrl_c,
InputAcceptedNow
));

Test("", Keys(
"\"$([int];\"_$(1+2)\")\"",
CheckThat(() =>
Expand Down