Skip to content

Fix hex color decorators for 3-digit and 4-digit hex colors #252338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 24, 2025

Hex colors were not showing color preview decorators for 3-digit (#RGB) and 4-digit (#RGBA) hex formats, even when properly quoted in strings. The regex pattern in defaultDocumentColorsComputer.ts only supported 6-digit (#RRGGBB) and 8-digit (#RRGGBBAA) hex colors.

Before

contentPrimary: '#FFFFFF',     // ✅ Shows color decorator (6-digit)
contentSecondary: '#abc',      // ❌ No color decorator (3-digit) 
contentTertiary: '#abcd',      // ❌ No color decorator (4-digit)
contentError: '#ED4964AB',     // ✅ Shows color decorator (8-digit)

After

contentPrimary: '#FFFFFF',     // ✅ Shows color decorator (6-digit)
contentSecondary: '#abc',      // ✅ Shows color decorator (3-digit) 
contentTertiary: '#abcd',      // ✅ Shows color decorator (4-digit)
contentError: '#ED4964AB',     // ✅ Shows color decorator (8-digit)

Changes Made

  1. Updated regex pattern in defaultDocumentColorsComputer.ts to include:

    • 3-digit hex colors: #RGB (expands to #RRGGBB)
    • 4-digit hex colors: #RGBA (expands to #RRGGBBAA)
  2. Added comprehensive test cases covering all hex color formats

  3. Maintained security measures - preserved existing whitespace/quote prefix requirements to prevent GitHub issue numbers from being detected as colors

Security Considerations

The fix maintains the existing security behavior:

  • background: '#abc' - Shows decorator (quoted)
  • color: #abc - Shows decorator (space prefix)
  • issue#abc123 - No decorator (no space/quote prefix)

The Color.Format.CSS.parseHex function already supports 3-digit and 4-digit hex parsing, so no changes were needed to the color parsing logic.

Fixes #239446.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • electronjs.org
    • Triggering command: node-gyp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: aiday-mar <61460952+aiday-mar@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Color decorator not working for hex colors Fix hex color decorators for 3-digit and 4-digit hex colors Jun 24, 2025
@Copilot Copilot AI requested a review from aiday-mar June 24, 2025 21:23
Copilot finished work on behalf of aiday-mar June 24, 2025 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Color decorator not working for hex colors
2 participants