fix(cli): ensure both light and dark themes are saved in the theme dialog

This commit is contained in:
Dan Zaharia
2026-03-04 11:27:00 -05:00
parent a32322dd06
commit 3013a0acb5
2 changed files with 51 additions and 7 deletions
+30 -7
View File
@@ -31,6 +31,8 @@ interface ThemeDialogProps {
onSelect: ( onSelect: (
themeName: string, themeName: string,
scope: LoadableSettingScope, scope: LoadableSettingScope,
themeMode?: 'light' | 'dark',
otherThemeName?: string,
) => void | Promise<void>; ) => void | Promise<void>;
/** Callback function when the dialog is cancelled */ /** Callback function when the dialog is cancelled */
@@ -44,7 +46,10 @@ interface ThemeDialogProps {
terminalWidth: number; terminalWidth: number;
} }
import { resolveColor , getThemeTypeFromBackgroundColor } from '../themes/color-utils.js'; import {
resolveColor,
getThemeTypeFromBackgroundColor,
} from '../themes/color-utils.js';
import { DefaultLight } from '../themes/default-light.js'; import { DefaultLight } from '../themes/default-light.js';
import { DefaultDark } from '../themes/default.js'; import { DefaultDark } from '../themes/default.js';
@@ -137,10 +142,19 @@ export function ThemeDialog({
const handleThemeSelect = useCallback( const handleThemeSelect = useCallback(
async (themeName: string) => { async (themeName: string) => {
// @ts-expect-error adding extra argument for the updated hook const otherThemeName =
await onSelect(themeName, selectedScope, activeTab); activeTab === 'light'
? highlightedThemeNameDark
: highlightedThemeNameLight;
await onSelect(themeName, selectedScope, activeTab, otherThemeName);
}, },
[onSelect, selectedScope, activeTab], [
onSelect,
selectedScope,
activeTab,
highlightedThemeNameDark,
highlightedThemeNameLight,
],
); );
const handleThemeHighlight = (themeName: string) => { const handleThemeHighlight = (themeName: string) => {
@@ -158,10 +172,19 @@ export function ThemeDialog({
const handleScopeSelect = useCallback( const handleScopeSelect = useCallback(
async (scope: LoadableSettingScope) => { async (scope: LoadableSettingScope) => {
// @ts-expect-error adding extra argument const otherThemeName =
await onSelect(highlightedThemeName, scope, activeTab); activeTab === 'light'
? highlightedThemeNameDark
: highlightedThemeNameLight;
await onSelect(highlightedThemeName, scope, activeTab, otherThemeName);
}, },
[onSelect, highlightedThemeName, activeTab], [
onSelect,
highlightedThemeName,
activeTab,
highlightedThemeNameDark,
highlightedThemeNameLight,
],
); );
const [mode, setMode] = useState<'theme' | 'scope'>('theme'); const [mode, setMode] = useState<'theme' | 'scope'>('theme');
@@ -26,6 +26,7 @@ interface UseThemeCommandReturn {
themeName: string, themeName: string,
scope: LoadableSettingScope, scope: LoadableSettingScope,
themeMode?: 'light' | 'dark', themeMode?: 'light' | 'dark',
otherThemeName?: string,
) => Promise<void>; ) => Promise<void>;
handleThemeHighlight: (themeName: string | undefined) => void; handleThemeHighlight: (themeName: string | undefined) => void;
} }
@@ -99,6 +100,7 @@ export const useThemeCommand = (
themeName: string, themeName: string,
scope: LoadableSettingScope, scope: LoadableSettingScope,
themeMode?: 'light' | 'dark', themeMode?: 'light' | 'dark',
otherThemeName?: string,
) => { ) => {
try { try {
const mergedCustomThemes = { const mergedCustomThemes = {
@@ -114,10 +116,29 @@ export const useThemeCommand = (
return; return;
} }
if (otherThemeName) {
const isBuiltInOther = themeManager.findThemeByName(otherThemeName);
const isCustomOther =
otherThemeName && mergedCustomThemes[otherThemeName];
if (!isBuiltInOther && !isCustomOther) {
setThemeError(
`Theme "${otherThemeName}" not found in selected scope.`,
);
setIsThemeDialogOpen(true);
return;
}
}
if (themeMode === 'light') { if (themeMode === 'light') {
loadedSettings.setValue(scope, 'ui.themeLight', themeName); loadedSettings.setValue(scope, 'ui.themeLight', themeName);
if (otherThemeName) {
loadedSettings.setValue(scope, 'ui.themeDark', otherThemeName);
}
} else if (themeMode === 'dark') { } else if (themeMode === 'dark') {
loadedSettings.setValue(scope, 'ui.themeDark', themeName); loadedSettings.setValue(scope, 'ui.themeDark', themeName);
if (otherThemeName) {
loadedSettings.setValue(scope, 'ui.themeLight', otherThemeName);
}
} else { } else {
loadedSettings.setValue(scope, 'ui.themeLight', themeName); loadedSettings.setValue(scope, 'ui.themeLight', themeName);
loadedSettings.setValue(scope, 'ui.themeDark', themeName); loadedSettings.setValue(scope, 'ui.themeDark', themeName);