mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 14:10:37 -07:00
fix(cli): resolve autoThemeSwitching when background hasn't changed but theme mismatches (#20706)
This commit is contained in:
@@ -196,6 +196,36 @@ describe('useTerminalTheme', () => {
|
||||
expect(mockHandleThemeSelect).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should switch theme even if terminal background report is identical to previousColor if current theme is mismatched', () => {
|
||||
// Background is dark at startup
|
||||
config.setTerminalBackground('#000000');
|
||||
vi.mocked(config.setTerminalBackground).mockClear();
|
||||
// But theme is light
|
||||
mockSettings.merged.ui.theme = 'default-light';
|
||||
|
||||
const refreshStatic = vi.fn();
|
||||
const { unmount } = renderHook(() =>
|
||||
useTerminalTheme(mockHandleThemeSelect, config, refreshStatic),
|
||||
);
|
||||
|
||||
const handler = mockSubscribe.mock.calls[0][0];
|
||||
|
||||
// Terminal reports the same dark background
|
||||
handler('rgb:0000/0000/0000');
|
||||
|
||||
expect(config.setTerminalBackground).not.toHaveBeenCalled();
|
||||
expect(themeManager.setTerminalBackground).not.toHaveBeenCalled();
|
||||
expect(refreshStatic).not.toHaveBeenCalled();
|
||||
// But it SHOULD select the dark theme because of the mismatch!
|
||||
expect(mockHandleThemeSelect).toHaveBeenCalledWith(
|
||||
'default',
|
||||
expect.anything(),
|
||||
);
|
||||
|
||||
mockSettings.merged.ui.theme = 'default';
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('should not switch theme if autoThemeSwitching is disabled', () => {
|
||||
mockSettings.merged.ui.autoThemeSwitching = false;
|
||||
const { unmount } = renderHook(() =>
|
||||
|
||||
@@ -59,14 +59,6 @@ export function useTerminalTheme(
|
||||
if (!hexColor) return;
|
||||
|
||||
const previousColor = config.getTerminalBackground();
|
||||
|
||||
if (previousColor === hexColor) {
|
||||
return;
|
||||
}
|
||||
|
||||
config.setTerminalBackground(hexColor);
|
||||
themeManager.setTerminalBackground(hexColor);
|
||||
|
||||
const luminance = getLuminance(hexColor);
|
||||
const currentThemeName = settings.merged.ui.theme;
|
||||
|
||||
@@ -77,6 +69,16 @@ export function useTerminalTheme(
|
||||
DefaultLight.name,
|
||||
);
|
||||
|
||||
if (previousColor === hexColor) {
|
||||
if (newTheme) {
|
||||
void handleThemeSelect(newTheme, SettingScope.User);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
config.setTerminalBackground(hexColor);
|
||||
themeManager.setTerminalBackground(hexColor);
|
||||
|
||||
if (newTheme) {
|
||||
void handleThemeSelect(newTheme, SettingScope.User);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user