mirror of
https://github.com/PowerShell/PSReadLine
synced 2026-06-08 12:12:13 +00:00
Prioritize highlight of command names, prevent bleed from aligned nested tokens (#989)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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(() =>
|
||||
|
||||
Reference in New Issue
Block a user