vscode: Color decorator not working for hex colors
Type: Bug
Hex colors no longer show a preview, likely from this change: https://github.com/microsoft/vscode/pull/233306
If a string begins with “#” without a leading whitespace, it should be a candidate for color preview. In the following code, rgb values show a preview, hex values do not.
contentPrimary: '#FFFFFF',
contentSecondary: 'rgba(255, 255, 255, 0.75)',
contentTertiary: 'rgba(255, 255, 255, 0.62)',
contentDisabled: 'rgba(255, 255, 255, 0.62)',
contentError: '#ED4964',
VS Code version: Code 1.96.4 (Universal) (cd4ee3b1c348a13bafd8f9ad8060705f6d4b9cba, 2025-01-16T00:16:19.038Z) OS version: Darwin arm64 24.2.0 Modes:
System Info
| Item | Value |
|---|---|
| CPUs | Apple M4 (10 x 2400) |
| GPU Status | 2d_canvas: enabled canvas_oop_rasterization: enabled_on direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_graphite: disabled_off video_decode: enabled video_encode: enabled webgl: enabled webgl2: enabled webgpu: enabled webnn: disabled_off |
| Load (avg) | 1, 1, 1 |
| Memory (System) | 24.00GB (0.65GB free) |
| Process Argv | –crash-reporter-id 6d4ed78e-0cd6-432b-b48c-8ea5665c6a2a |
| Screen Reader | no |
| VM | 0% |
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyt551:31179978
vscod805:30301674
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30959799
pythonnoceb:30805159
pythonmypyd1:30879173
h48ei257:31000450
pythontbext0:30879054
cppperfnew:31000557
dwnewjupyter:31046869
nativerepl2:31139839
pythonrstrctxt:31112756
nativeloc2:31192216
iacca1:31171482
5fd0e150:31155592
dwcopilot:31170013
stablechunks:31184530
6074i472:31201624
dwoutputs:31217127
9064b325:31222308
copilot_t_ci:31222730
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 7
- Comments: 17 (4 by maintainers)
I’m sorry but this doesn’t make any sense. What you describe is not valid code. A standalone string like I posted in my sample should be recognized as a color. Having " #ffffff".substring(1) would be absurd.
Hi yes this is expected and happens so that we limit mistaking github issue numbers for colors. The way we do this is to enforce having at least one space before the hex value.
I am having this same issue, and will note that when you add a space after the quote, the color decorator appears:
Hi everyone thanks for commenting. I was just discussing this with my team this morning. Would the following fix then work for you?
If a hex value is inside of a string, just render the color decorators always. If the hex value is outside of a string, enforce that it is prefixed with a whitespace.
I agree with this, I heavily use JSON files to have the static data like colors, and due to this change I can’t see any color decorators in my whole while. And adding an extra space after quote changes the meaning of the code which I can’t do. I had to install external extension but that is showing colors in overview ruler as well.
Same problem with json files: “line_color”: “#f00000”, with a space it works
@aiday-mar We are talking not about regular
.cssbut about the.jsxand.tsxfiles:And this is huge and affects every React developer i believe. 🤔
StackBlitz: https://stackblitz.com/edit/react-veovewjj?file=src%2FApp.js
I just verified and this works on the nightly insiders release, after the PR https://github.com/microsoft/vscode/pull/251589 was merged last month. You should see this work correctly in the next stable release. Closing this issue but feel free to comment more for other cases where you consider the color decorator should show.
This is not something I can do as it is not in my skill-set yet 😄
I’m also seeing this on my end. It works fine for the rgba value, but not for the hex. If I add a space before the #, it will show up, but thats not a solution… I don’t understand how anyone would look at this and say it’s “by design”.