From 581c8cf02544b74e6ea6f5bc2e8c67893ec80e93 Mon Sep 17 00:00:00 2001 From: audichuang <72485427+audichuang@users.noreply.github.com> Date: Fri, 27 Nov 2026 16:41:56 +0800 Subject: [PATCH] fix(editor): show color swatches for HTML style attributes and embedded scripts (#6412) Named colors only counted in style sheet languages, and in markup only matches inside style nodes were kept, so embedded script code was dropped. Named colors now count in markup (still limited to ", + "", + '
', + "red: blue
", + ].join("\n"), + "html", + ), + ).toEqual(["white", "#f0f8ff", "red", "#abc"]); + expect( + swatchTitles( + '\nx', + "vue", + ), + ).toEqual(["#1b766c", "red"]); +}); + it("updates a CSS literal from alpha and hex fields and ignores invalid input", async () => { view = new EditorView({ state: EditorState.create({ diff --git a/src/features/color-preview/gutter.ts b/src/features/color-preview/gutter.ts index ad8396e8e..477af84a8 100644 --- a/src/features/color-preview/gutter.ts +++ b/src/features/color-preview/gutter.ts @@ -78,10 +78,16 @@ export function lineColor(state: EditorState, pos: number, language: string): Co const matches = findColors(line.text, language, isColorName); if (!isMarkupLanguage(language)) return matches[0] ?? null; const tree = syntaxTree(state); + let script: ColorMatch[] | undefined; return ( matches.find((color) => { let node: ReturnType