Skip to content

Commit 8baec4f

Browse files
authored
Only show default color decorators for length 6 and length 8 hex values (microsoft#233094)
only show default color decorators for length 6 and length 8 hex values
1 parent bcd6c1d commit 8baec4f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/vs/editor/common/languages/defaultDocumentColorsComputer.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,15 @@ function _findRange(model: IDocumentColorComputerTarget, match: RegExpMatchArray
4949
return range;
5050
}
5151

52-
function _findHexColorInformation(range: IRange | undefined, hexValue: string) {
52+
function _findHexColorInformation(range: IRange | undefined, hexSchema: string, hexParameters: string) {
5353
if (!range) {
5454
return;
5555
}
56+
// Even though length 3 and 4 hex values are valid, do not show default color decorators for these lengths
57+
if (hexParameters.length !== 6 && hexParameters.length !== 8) {
58+
return;
59+
}
60+
const hexValue = hexSchema + hexParameters;
5661
const parsedHexColor = Color.Format.CSS.parseHex(hexValue);
5762
if (!parsedHexColor) {
5863
return;
@@ -127,7 +132,7 @@ function computeColors(model: IDocumentColorComputerTarget): IColorInformation[]
127132
const regexParameters = /^\(\s*(36[0]|3[0-5][0-9]|[12][0-9][0-9]|[1-9]?[0-9])\s*,\s*(100|\d{1,2}[.]\d*|\d{1,2})%\s*,\s*(100|\d{1,2}[.]\d*|\d{1,2})%\s*,\s*(0[.][0-9]+|[.][0-9]+|[01][.]|[01])\s*\)$/gm;
128133
colorInformation = _findHSLColorInformation(_findRange(model, initialMatch), _findMatches(colorParameters, regexParameters), true);
129134
} else if (colorScheme === '#') {
130-
colorInformation = _findHexColorInformation(_findRange(model, initialMatch), colorScheme + colorParameters);
135+
colorInformation = _findHexColorInformation(_findRange(model, initialMatch), colorScheme, colorParameters);
131136
}
132137
if (colorInformation) {
133138
result.push(colorInformation);

0 commit comments

Comments
 (0)