Skip to content

feat(web): preview colors in code blocks - #7979

Open
msegec wants to merge 3 commits into
pingdotgg:mainfrom
msegec:feat/code-color-previews
Open

feat(web): preview colors in code blocks#7979
msegec wants to merge 3 commits into
pingdotgg:mainfrom
msegec:feat/code-color-previews

Conversation

@msegec

@msegec msegec commented Aug 23, 2026

Copy link
Copy Markdown

CSS hex values in agent code blocks were text-only, which made related theme colours hard to compare at a glance.

This adds a small swatch beside valid #RGB, #RGBA, #RRGGBB, and #RRGGBBAA values in web and desktop chat. The swatch enlarges on hover. It is added only to Shiki's rendered preview, so the source and copied code stay unchanged.

UI changes

Valid hex colours now show a compact preview beside the literal. Invalid lengths and hashes embedded in identifiers are left alone.

Testing

  • vp test run apps/web/src/lib/codeColorPreviews.test.ts apps/web/src/components/ChatMarkdown.test.tsx apps/web/src/markdown-clipboard.test.ts (15 tests)
  • vp lint --type-aware --type-check apps/web/src/components/ChatMarkdown.tsx apps/web/src/lib/codeColorPreviews.ts apps/web/src/lib/codeColorPreviews.test.ts
  • vp run --filter @t3tools/web typecheck
  • vp fmt --check apps/web/src/components/ChatMarkdown.tsx apps/web/src/index.css apps/web/src/lib/codeColorPreviews.ts apps/web/src/lib/codeColorPreviews.test.ts
  • Isolated web client: verified five valid colour formats, invalid values ignored, unchanged code text, decorative accessibility output, and the 1.6x hover state

Built with GPT-5.6 Sol in T3 Code using the Codex harness.


Note

Low Risk
UI-only highlighting change with regex-gated hex values injected into existing Shiki HTML. No auth, data, or copy-path changes.

Overview
Adds inline color swatches next to CSS hex literals in highlighted chat code blocks so theme colors are easier to compare at a glance. Source text and copy stay unchanged; swatches are decorative (aria-hidden) and scale up on hover.

A Shiki transformer in codeColorPreviews wraps standalone #rgb/#rgba/#rrggbb/#rrggbbaa tokens. Style languages (CSS, HTML, Vue, etc.) get short and long forms; JS/TS/JSON/YAML/TOML only get 6/8-digit hex to avoid issue refs and private names. Other languages and plaintext highlight fallbacks get no swatches. Invalid lengths and hashes inside identifiers are ignored.

Reviewed by Cursor Bugbot for commit c550a28. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Add hex color swatch previews in highlighted code blocks

  • Adds codeColorPreviewParts parser and createCodeColorPreviewTransformer factory in codeColorPreviews.ts that detect CSS hex colors in Shiki spans and wrap them in .chat-markdown-color-literal / .chat-markdown-color-swatch markup
  • codeColorPreviewTransformers selects transformers per language: short-hex support for style/template languages, long-hex-only for data/script languages, none for others
  • UncachedShikiCodeBlock in ChatMarkdown.tsx passes these transformers to highlighter.codeToHtml; the plain-text fallback path applies no transformers
  • Adds theme-aware border, inline-block swatch, and hover-scale styles in index.css for the new classes
  • Behavioral Change: Shiki span output for supported languages now contains extra <span> elements around hex color literals; consumers parsing rendered HTML may see the added markup

Macroscope summarized c550a28.

Render swatches through Shiki token output so source and copied code stay unchanged.
@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8a33e22b-9362-4c27-a972-634b64bb5f2c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 23, 2026
Comment thread apps/web/src/lib/codeColorPreviews.ts Outdated

@macroscopeapp macroscopeapp Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI consistency review found two issues in the new code-colour preview chrome: a themed-palette token mismatch for the swatch border, and swatch injection into non-colour tokens in generated markdown code blocks. Details inline.

Posted via Macroscope — UI Consistency

Comment thread apps/web/src/lib/codeColorPreviews.ts Outdated
Comment thread apps/web/src/index.css

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4ce7faf. Configure here.

Comment thread apps/web/src/lib/codeColorPreviews.ts Outdated
@macroscopeapp

macroscopeapp Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Skipped

Macroscope did not run approvability analysis for this PR. Macroscope could not determine whether this PR modifies its approvability configuration, so the PR was not approved automatically. A PR that may change the rules that govern approval is never approved automatically.

…rs readable

The hex regex only rejected trailing hex digits, so identifiers such as
#define, #fffxyz, and #fff-theme grew a swatch mid-word. The trailing
lookahead now mirrors the leading boundary.

The transformer ran on every language including the plain-text fallback,
where a whole line is one token, so prose and issue references in
unknown-language fences were scanned. Previews are now enabled only for
languages that plausibly carry CSS colours, and the fallback renders
without them.

The swatch border mixed --contrast-foreground while themed palettes
repaint the code surface, washing it out on custom themes. A themed
counterpart now follows --code-foreground like the rest of the
code-block chrome.

@macroscopeapp macroscopeapp Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One remaining false-positive case in the colour-preview matcher; the earlier theming and plain-text-fallback concerns look resolved.

Posted via Macroscope — UI Consistency

Comment thread apps/web/src/lib/codeColorPreviews.ts
In script and data languages a 3- or 4-digit hex run is usually an issue
reference in a comment or a JS private name, so those languages now only
preview #rrggbb/#rrggbbaa. Style languages keep the short forms, where
they are real colours.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant