Prioritize highlight of command names, prevent bleed from aligned nested tokens (#989)

This commit is contained in:
Carl Morris
2019-09-06 13:37:28 -07:00
committed by Dongbo Wang
parent 4285cce99c
commit 820f1607d6
2 changed files with 39 additions and 6 deletions
+6 -6
View File
@@ -215,7 +215,7 @@ namespace Microsoft.PowerShell
// 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])
{
@@ -630,6 +630,11 @@ namespace Microsoft.PowerShell
private string GetTokenColor(Token token)
{
if ((token.TokenFlags & TokenFlags.CommandName) != 0)
{
return _options._commandColor;
}
switch (token.Kind)
{
case TokenKind.Comment:
@@ -653,11 +658,6 @@ namespace Microsoft.PowerShell
return _options._numberColor;
}
if ((token.TokenFlags & TokenFlags.CommandName) != 0)
{
return _options._commandColor;
}
if ((token.TokenFlags & TokenFlags.Keyword) != 0)
{
return _options._keywordColor;
+33
View File
@@ -61,6 +61,39 @@ namespace Test
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(() =>