refactor(cli): fully remove React anti patterns, improve type safety and fix UX oversights in SettingsDialog.tsx (#18963)

Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
Pyush Sinha
2026-03-02 13:30:58 -08:00
committed by GitHub
parent 18d0375a7f
commit 8133d63ac6
14 changed files with 589 additions and 1390 deletions
@@ -12,6 +12,7 @@ import type {
SettingsFile,
} from '../../config/settings.js';
import { SettingScope } from '../../config/settings.js';
import { checkExhaustive } from '@google/gemini-cli-core';
export const SettingsContext = React.createContext<LoadedSettings | undefined>(
undefined,
@@ -66,7 +67,7 @@ export const useSettingsStore = (): SettingsStoreValue => {
case SettingScope.SystemDefaults:
return snapshot.systemDefaults;
default:
throw new Error(`Invalid scope: ${scope}`);
checkExhaustive(scope);
}
},
}),
@@ -4,15 +4,9 @@
* SPDX-License-Identifier: Apache-2.0
*/
import {
createContext,
useCallback,
useContext,
useEffect,
useState,
} from 'react';
import type { LoadedSettings } from '../../config/settings.js';
import { createContext, useCallback, useContext, useState } from 'react';
import { SettingScope } from '../../config/settings.js';
import { useSettingsStore } from './SettingsContext.js';
export type VimMode = 'NORMAL' | 'INSERT';
@@ -27,35 +21,22 @@ const VimModeContext = createContext<VimModeContextType | undefined>(undefined);
export const VimModeProvider = ({
children,
settings,
}: {
children: React.ReactNode;
settings: LoadedSettings;
}) => {
const initialVimEnabled = settings.merged.general.vimMode;
const [vimEnabled, setVimEnabled] = useState(initialVimEnabled);
const { settings, setSetting } = useSettingsStore();
const vimEnabled = settings.merged.general.vimMode;
const [vimMode, setVimMode] = useState<VimMode>('INSERT');
useEffect(() => {
// Initialize vimEnabled from settings on mount
const enabled = settings.merged.general.vimMode;
setVimEnabled(enabled);
// When vim mode is enabled, start in INSERT mode
if (enabled) {
setVimMode('INSERT');
}
}, [settings.merged.general.vimMode]);
const toggleVimEnabled = useCallback(async () => {
const newValue = !vimEnabled;
setVimEnabled(newValue);
// When enabling vim mode, start in INSERT mode
if (newValue) {
setVimMode('INSERT');
}
settings.setValue(SettingScope.User, 'general.vimMode', newValue);
setSetting(SettingScope.User, 'general.vimMode', newValue);
return newValue;
}, [vimEnabled, settings]);
}, [vimEnabled, setSetting]);
const value = {
vimEnabled,