@devries-cameron20 / t3code Mirror · read-only / commits / e25a337e5f
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

fix(web): keep long-named VS Code themes separate on import (#39493)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Soroush Baraouf committed Nov 19, 2026 at 22:42 UTC e25a337e5fbf6270f27774759c59f09b8460ccd5
2 files changed +113 -2
apps/web/src/vscodeThemeImport.test.ts
+95
@@ -537,4 +537,99 @@ describe("VS Code theme import", () => {
537 expect(numbered.map((theme) => theme.label)).toEqual(["Dracula", "Dracula 2"]);
538 expect(numbered.map((theme) => theme.css)).toEqual([css, css]);
539 });
540 +
541 + const darkVsCodeTheme = (name: string, background: string) =>
542 + parseVsCodeThemeFile({
543 + name,
544 + type: "dark",
545 + colors: { "editor.background": background, "editor.foreground": "#cdd6f4" },
546 + });
547 +
548 + it("keeps both digits of a suffix when a one-digit suffix just fits", () => {
549 + const name = "GitHub Dark High Contrast Deuteranopia Preview";
550 + const backgrounds = [
551 + "#1e1e2e",
552 + "#25203b",
553 + "#152a26",
554 + "#181825",
555 + "#11111b",
556 + "#232136",
557 + "#101014",
558 + "#24273a",
559 + "#282a36",
560 + "#22232e",
561 + ];
562 + const themes = resolveThemeLabelCollisions(
563 + backgrounds.map((background) => ({ theme: darkVsCodeTheme(name, background) })),
564 + );
565 + expect(themes.map((theme) => theme.label)).toEqual([
566 + name,
567 + ...Array.from({ length: 8 }, (_, index) => `${name} ${index + 2}`),
568 + "GitHub Dark High Contrast Deuteranopia Previe 10",
569 + ]);
570 + expect(new Set(themes.map((theme) => theme.id)).size).toBe(backgrounds.length);
571 + });
572 +
573 + it.each([
574 + {
575 + name: "Catppuccin Mocha High Contrast Accessible v2 🌙",
576 + numberedBase: "Catppuccin Mocha High Contrast Accessible v2",
577 + },
578 + {
579 + name: "İstanbul İncisi İzmir İskenderun İnegöl İpsala",
580 + numberedBase: "İstanbul İncisi İzmir İskenderun İnegöl İ",
581 + },
582 + ])("keeps all numbered variants of $name", ({ name, numberedBase }) => {
583 + const themes = resolveThemeLabelCollisions(
584 + ["#1e1e2e", "#25203b", "#152a26"].map((background) => ({
585 + theme: darkVsCodeTheme(name, background),
586 + })),
587 + );
588 + expect(themes.map((theme) => theme.label)).toEqual([
589 + name,
590 + `${numberedBase} 2`,
591 + `${numberedBase} 3`,
592 + ]);
593 + expect(new Set(themes.map((theme) => theme.id)).size).toBe(3);
594 + });
595 +
596 + it("does not take the ID of a later theme already named with that number", () => {
597 + const name = "Catppuccin Mocha High Contrast Accessible Themes";
598 + const numberedBase = "Catppuccin Mocha High Contrast Accessible Them";
599 + const duplicates = ["#1e1e2e", "#25203b"].map((background) => ({
600 + theme: darkVsCodeTheme(name, background),
601 + }));
602 + const peer = { theme: darkVsCodeTheme(`${numberedBase} 2`, "#152a26") };
603 + const themes = resolveThemeLabelCollisions([...duplicates, peer]);
604 + expect(themes.map(({ label }) => label)).toEqual([
605 + name,
606 + `${numberedBase} 3`,
607 + `${numberedBase} 2`,
608 + ]);
609 + expect(themes.find(({ id }) => id === peer.theme.id)?.colors.canvas).toBe(
610 + peer.theme.colors.canvas,
611 + );
612 + });
613 +
614 + it("makes the appended number reach the ID when the name already contains that number", () => {
615 + const name = "İzmir İzmit İznik İğdır İdil İspir İncir 2 Ö";
616 + const themes = resolveThemeLabelCollisions(
617 + ["#1e1e2e", "#25203b"].map((canvas) => ({
618 + theme: parseThemeFile({
619 + version: THEME_FILE_VERSION,
620 + id: "izmir-nightfall",
621 + name,
622 + appearance: "dark",
623 + colors: { canvas },
624 + }),
625 + })),
626 + );
627 + expect(themes.map(({ label, id }) => [label, id])).toEqual([
628 + [name, "izmir-nightfall"],
629 + [
630 + "İzmir İzmit İznik İğdır İdil İspir İncir 2",
631 + "i-zmir-i-zmit-i-znik-i-d-r-i-dil-i-spir-i-ncir-2",
632 + ],
633 + ]);
634 + });
635 });
apps/web/src/vscodeThemeImport.ts
+18 -2
@@ -480,6 +480,7 @@ export function resolveThemeLabelCollisions(
480 return renamed ?? theme;
481 });
482
483 + const inputIds = new Set(relabelled.map(({ id }) => id));
484 const seen = new Set<string>();
485 return relabelled.map((theme) => {
486 if (!seen.has(theme.id)) {
@@ -487,8 +488,23 @@ export function resolveThemeLabelCollisions(
488 return theme;
489 }
490 for (let suffix = 2; suffix < 100; suffix += 1) {
490 - const candidate = rename(theme, `${theme.label} ${suffix}`);
491 - if (candidate && !seen.has(candidate.id)) {
491 + const suffixText = String(suffix);
492 + const base = [...theme.label];
493 + let stem = base.join("").trimEnd();
494 + let name = `${stem} ${suffixText}`;
495 + let id = themeIdFromName(name);
496 + while (
497 + name.length > 48 ||
498 + id.split("-").at(-1) !== suffixText ||
499 + id === themeIdFromName(stem)
500 + ) {
501 + base.pop();
502 + stem = base.join("").trimEnd();
503 + name = `${stem} ${suffixText}`;
504 + id = themeIdFromName(name);
505 + }
506 + const candidate = rename(theme, name);
507 + if (candidate && !inputIds.has(candidate.id) && !seen.has(candidate.id)) {
508 seen.add(candidate.id);
509 return candidate;
510 }