fix(cli): restore previous theme on /theme cancel (refs #2833)

This commit is contained in:
KULIKRCH_HUAWEI\rocks 2026-04-02 17:38:35 +03:00
parent 92f7549bdc
commit 0104569fdd
2 changed files with 68 additions and 1 deletions

View file

@ -29,6 +29,9 @@ export const useThemeCommand = (
): UseThemeCommandReturn => {
const [isThemeDialogOpen, setIsThemeDialogOpen] =
useState(!!initialThemeError);
const [themeBeforeDialogOpen, setThemeBeforeDialogOpen] = useState<
string | undefined
>(themeManager.getActiveTheme().name);
const openThemeDialog = useCallback(() => {
if (process.env['NO_COLOR']) {
@ -43,6 +46,9 @@ export const useThemeCommand = (
);
return;
}
// The theme may temporarily change while navigating the list; keep the
// original value to restore it if user cancels with Esc/Ctrl+C.
setThemeBeforeDialogOpen(themeManager.getActiveTheme().name);
setIsThemeDialogOpen(true);
}, [addItem]);
@ -72,6 +78,14 @@ export const useThemeCommand = (
const handleThemeSelect = useCallback(
(themeName: string | undefined, scope: SettingScope) => {
// Undefined means "cancel": close dialog and restore original theme.
if (themeName === undefined) {
applyTheme(themeBeforeDialogOpen);
setThemeError(null);
setIsThemeDialogOpen(false);
return;
}
try {
// Merge user and workspace custom themes (workspace takes precedence)
const mergedCustomThemes = {
@ -100,7 +114,7 @@ export const useThemeCommand = (
setIsThemeDialogOpen(false); // Close the dialog
}
},
[applyTheme, loadedSettings, setThemeError],
[applyTheme, loadedSettings, setThemeError, themeBeforeDialogOpen],
);
return {