Changesets · Branches · Tags · Compare
| Changeset | 94f7b85f6068e2b40c4fdaeded6de4438bd772cdcd6cc3323bafc40a844ba60f |
|---|---|
| Author | Jacob Kim <jacob@continue.dev> · 2025-08-15 14:46 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-08-15 14:46 -07:00 |
| Parents | 4e3281ed77e4 |
3 files changed
modified core/codeRenderer/CodeRenderer.ts +16 −15
| @@ -20,7 +20,7 @@ | ||
| 20 | 20 | Highlighter, |
| 21 | 21 | } from "shiki"; |
| 22 | 22 | import { DiffLine } from ".."; |
| 23 | -import { escapeForSVG, kebabOfStr } from "../util/text"; | |
| 23 | +import { escapeForSVG, kebabOfThemeStr } from "../util/text"; | |
| 24 | 24 | |
| 25 | 25 | interface CodeRendererOptions { |
| 26 | 26 | themesDir?: string; |
| @@ -70,28 +70,29 @@ | ||
| 70 | 70 | |
| 71 | 71 | public async setTheme(themeName: string): Promise<void> { |
| 72 | 72 | if ( |
| 73 | - this.themeExists(kebabOfStr(themeName)) || | |
| 73 | + this.themeExists(kebabOfThemeStr(themeName)) || | |
| 74 | 74 | themeName === "Default Dark Modern" |
| 75 | 75 | ) { |
| 76 | 76 | this.currentTheme = |
| 77 | 77 | themeName === "Default Dark Modern" |
| 78 | 78 | ? "dark-plus" |
| 79 | - : kebabOfStr(themeName); | |
| 80 | - | |
| 81 | - this.highlighter = await getSingletonHighlighter({ | |
| 82 | - langs: ["typescript"], | |
| 83 | - themes: [this.currentTheme], | |
| 84 | - }); | |
| 85 | - | |
| 86 | - const th = this.highlighter.getTheme(this.currentTheme); | |
| 87 | - | |
| 88 | - this.editorBackground = th.bg; | |
| 89 | - this.editorForeground = th.fg; | |
| 90 | - this.editorLineHighlight = | |
| 91 | - th.colors!["editor.lineHighlightBackground"] ?? "#000000"; | |
| 79 | + : kebabOfThemeStr(themeName); | |
| 92 | 80 | } else { |
| 81 | + // Fallback to default theme for unsupported themes. | |
| 93 | 82 | this.currentTheme = "dark-plus"; |
| 94 | 83 | } |
| 84 | + | |
| 85 | + // Always initialize the highlighter with the current theme. | |
| 86 | + this.highlighter = await getSingletonHighlighter({ | |
| 87 | + langs: ["typescript"], | |
| 88 | + themes: [this.currentTheme], | |
| 89 | + }); | |
| 90 | + | |
| 91 | + const th = this.highlighter.getTheme(this.currentTheme); | |
| 92 | + this.editorBackground = th.bg; | |
| 93 | + this.editorForeground = th.fg; | |
| 94 | + this.editorLineHighlight = | |
| 95 | + th.colors!["editor.lineHighlightBackground"] ?? "#000000"; | |
| 95 | 96 | } |
| 96 | 97 | |
| 97 | 98 | async init(): Promise<void> {} |
modified core/util/text.ts +7 −0
| @@ -44,3 +44,10 @@ | ||
| 44 | 44 | .replace(/[\s_]+/g, "-") // replace spaces and underscores with hyphens |
| 45 | 45 | .toLowerCase(); |
| 46 | 46 | } |
| 47 | + | |
| 48 | +export function kebabOfThemeStr(str: string): string { | |
| 49 | + return str | |
| 50 | + .toLowerCase() | |
| 51 | + .replace(/[\s_]+/g, "-") // replace spaces and underscores with hyphens | |
| 52 | + .replace(/\(|\)/g, ""); // remove parentheses | |
| 53 | +} |
modified core/util/text.vitest.ts +58 −0
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | capitalizeFirstLetter, |
| 4 | 4 | escapeForSVG, |
| 5 | 5 | kebabOfStr, |
| 6 | + kebabOfThemeStr, | |
| 6 | 7 | replaceEscapedCharacters, |
| 7 | 8 | } from "./text"; |
| 8 | 9 | |
| @@ -184,3 +185,60 @@ | ||
| 184 | 185 | expect(kebabOfStr("MiXeD cAsE")).toBe("mi-xe-d-c-as-e"); |
| 185 | 186 | }); |
| 186 | 187 | }); |
| 188 | + | |
| 189 | +describe("kebabOfThemeStr", () => { | |
| 190 | + it("should convert spaces to hyphens", () => { | |
| 191 | + expect(kebabOfThemeStr("hello world")).toBe("hello-world"); | |
| 192 | + expect(kebabOfThemeStr("multiple spaces")).toBe("multiple-spaces"); | |
| 193 | + }); | |
| 194 | + | |
| 195 | + it("should convert underscores to hyphens", () => { | |
| 196 | + expect(kebabOfThemeStr("snake_case")).toBe("snake-case"); | |
| 197 | + expect(kebabOfThemeStr("multiple___underscores")).toBe( | |
| 198 | + "multiple-underscores", | |
| 199 | + ); | |
| 200 | + }); | |
| 201 | + | |
| 202 | + it("should convert mixed spaces and underscores", () => { | |
| 203 | + expect(kebabOfThemeStr("mixed_ case")).toBe("mixed-case"); | |
| 204 | + expect(kebabOfThemeStr("theme name_variant")).toBe("theme-name-variant"); | |
| 205 | + }); | |
| 206 | + | |
| 207 | + it("should convert to lowercase", () => { | |
| 208 | + expect(kebabOfThemeStr("UPPERCASE")).toBe("uppercase"); | |
| 209 | + expect(kebabOfThemeStr("MiXeD CaSe")).toBe("mixed-case"); | |
| 210 | + }); | |
| 211 | + | |
| 212 | + it("should handle already kebab-case strings", () => { | |
| 213 | + expect(kebabOfThemeStr("already-kebab")).toBe("already-kebab"); | |
| 214 | + }); | |
| 215 | + | |
| 216 | + it("should handle empty strings", () => { | |
| 217 | + expect(kebabOfThemeStr("")).toBe(""); | |
| 218 | + }); | |
| 219 | + | |
| 220 | + it("should handle single characters", () => { | |
| 221 | + expect(kebabOfThemeStr("A")).toBe("a"); | |
| 222 | + expect(kebabOfThemeStr("a")).toBe("a"); | |
| 223 | + }); | |
| 224 | + | |
| 225 | + it("should preserve other special characters", () => { | |
| 226 | + expect(kebabOfThemeStr("hello@world")).toBe("hello@world"); | |
| 227 | + expect(kebabOfThemeStr("test.file.name")).toBe("test.file.name"); | |
| 228 | + }); | |
| 229 | + | |
| 230 | + it("should not convert camelCase (unlike kebabOfStr)", () => { | |
| 231 | + expect(kebabOfThemeStr("camelCase")).toBe("camelcase"); | |
| 232 | + expect(kebabOfThemeStr("PascalCase")).toBe("pascalcase"); | |
| 233 | + }); | |
| 234 | + | |
| 235 | + it("should handle strings with numbers", () => { | |
| 236 | + expect(kebabOfThemeStr("theme_v2 beta")).toBe("theme-v2-beta"); | |
| 237 | + expect(kebabOfThemeStr("version_123_FINAL")).toBe("version-123-final"); | |
| 238 | + }); | |
| 239 | + | |
| 240 | + it("should handle strings with parentheses", () => { | |
| 241 | + expect(kebabOfThemeStr("theme_v2 (beta)")).toBe("theme-v2-beta"); | |
| 242 | + expect(kebabOfThemeStr("Gruvbox Dark (Hard)")).toBe("gruvbox-dark-hard"); | |
| 243 | + }); | |
| 244 | +}); |