Skip to content

Commit 820f160

Browse files
msftrncsdaxian-dbw
authored andcommitted
Prioritize highlight of command names, prevent bleed from aligned nested tokens (#989)
1 parent 4285cce commit 820f160

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

PSReadLine/Render.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ void MaybeEmphasize(int i, string currColor)
215215
// use the tokens color otherwise use the initial color.
216216
var state = tokenStack.Peek();
217217
var token = state.Tokens[state.Index];
218-
if (i == token.Extent.EndOffset)
218+
while (i == token.Extent.EndOffset)
219219
{
220220
if (token == state.Tokens[state.Tokens.Length - 1])
221221
{
@@ -630,6 +630,11 @@ private static int LengthInBufferCells(char c)
630630

631631
private string GetTokenColor(Token token)
632632
{
633+
if ((token.TokenFlags & TokenFlags.CommandName) != 0)
634+
{
635+
return _options._commandColor;
636+
}
637+
633638
switch (token.Kind)
634639
{
635640
case TokenKind.Comment:
@@ -653,11 +658,6 @@ private string GetTokenColor(Token token)
653658
return _options._numberColor;
654659
}
655660

656-
if ((token.TokenFlags & TokenFlags.CommandName) != 0)
657-
{
658-
return _options._commandColor;
659-
}
660-
661661
if ((token.TokenFlags & TokenFlags.Keyword) != 0)
662662
{
663663
return _options._keywordColor;

test/RenderTest.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,39 @@ public void Render()
6161
InputAcceptedNow
6262
));
6363

64+
// 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
65+
Test("", Keys(
66+
". -abc def;. abc$name -def",
67+
_.Home,
68+
CheckThat(() =>
69+
AssertScreenIs(1,
70+
TokenClassification.None, ". ",
71+
TokenClassification.Command, "-abc",
72+
TokenClassification.None, " def;. ",
73+
TokenClassification.Command, "abc",
74+
TokenClassification.Variable, "$name",
75+
TokenClassification.None, " ",
76+
TokenClassification.Parameter, "-def")),
77+
_.Ctrl_c,
78+
InputAcceptedNow
79+
));
80+
81+
// 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
82+
Test("", Keys(
83+
". ++ abc$name -def",
84+
_.Home,
85+
CheckThat(() =>
86+
AssertScreenIs(1,
87+
TokenClassification.None, ". ",
88+
TokenClassification.Command, "++",
89+
TokenClassification.None, " abc",
90+
TokenClassification.Variable, "$name",
91+
TokenClassification.None, " ",
92+
TokenClassification.Parameter, "-def")),
93+
_.Ctrl_c,
94+
InputAcceptedNow
95+
));
96+
6497
Test("", Keys(
6598
"\"$([int];\"_$(1+2)\")\"",
6699
CheckThat(() =>

0 commit comments

Comments
 (0)