summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/contexts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/cli/src/ui/contexts')
-rw-r--r--packages/cli/src/ui/contexts/SettingsContext.ts24
-rw-r--r--packages/cli/src/ui/contexts/VimModeContext.tsx5
2 files changed, 28 insertions, 1 deletions
diff --git a/packages/cli/src/ui/contexts/SettingsContext.ts b/packages/cli/src/ui/contexts/SettingsContext.ts
new file mode 100644
index 00000000..610a778d
--- /dev/null
+++ b/packages/cli/src/ui/contexts/SettingsContext.ts
@@ -0,0 +1,24 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import { createContext, useContext } from 'react';
+import { LoadedSettings } from '../../config/settings.js';
+
+export interface SettingsContextType {
+ settings: LoadedSettings;
+ recomputeSettings: () => void;
+}
+
+// This context is initialized in gemini.tsx with the loaded settings.
+export const SettingsContext = createContext<SettingsContextType | null>(null);
+
+export function useSettings(): LoadedSettings {
+ const context = useContext(SettingsContext);
+ if (!context) {
+ throw new Error('useSettings must be used within a SettingsProvider');
+ }
+ return context.settings;
+}
diff --git a/packages/cli/src/ui/contexts/VimModeContext.tsx b/packages/cli/src/ui/contexts/VimModeContext.tsx
index b27034ef..40de0b53 100644
--- a/packages/cli/src/ui/contexts/VimModeContext.tsx
+++ b/packages/cli/src/ui/contexts/VimModeContext.tsx
@@ -12,6 +12,7 @@ import {
useState,
} from 'react';
import { LoadedSettings, SettingScope } from '../../config/settings.js';
+import { SettingsContext } from './SettingsContext.js';
export type VimMode = 'NORMAL' | 'INSERT';
@@ -26,11 +27,13 @@ const VimModeContext = createContext<VimModeContextType | undefined>(undefined);
export const VimModeProvider = ({
children,
- settings,
+ settings: initialSettings,
}: {
children: React.ReactNode;
settings: LoadedSettings;
}) => {
+ const settingsContext = useContext(SettingsContext);
+ const settings = settingsContext?.settings || initialSettings;
const initialVimEnabled = settings.merged.vimMode ?? false;
const [vimEnabled, setVimEnabled] = useState(initialVimEnabled);
const [vimMode, setVimMode] = useState<VimMode>(