Skip to content

Commit d487f18

Browse files
committed
feat(webview-ui): add sticky modes setting to new miscellaneous section
1 parent bc34db1 commit d487f18

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { HTMLAttributes } from "react"
2+
import { useAppTranslation } from "@/i18n/TranslationContext"
3+
import { VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react"
4+
import { Settings } from "lucide-react"
5+
6+
import { SetCachedStateField } from "./types"
7+
import { SectionHeader } from "./SectionHeader"
8+
import { Section } from "./Section"
9+
10+
type MiscellaneousSettingsProps = HTMLAttributes<HTMLDivElement> & {
11+
stickyModesEnabled?: boolean
12+
setCachedStateField: SetCachedStateField<"stickyModesEnabled">
13+
}
14+
15+
export const MiscellaneousSettings = ({
16+
stickyModesEnabled,
17+
setCachedStateField,
18+
className,
19+
...props
20+
}: MiscellaneousSettingsProps) => {
21+
const { t } = useAppTranslation()
22+
23+
return (
24+
<div {...props}>
25+
<SectionHeader description={t("settings:miscellaneous.description")}>
26+
<div className="flex items-center gap-2">
27+
<Settings className="w-4" />
28+
<div>{t("settings:sections.miscellaneous")}</div>
29+
</div>
30+
</SectionHeader>
31+
32+
<Section>
33+
<div>
34+
<VSCodeCheckbox
35+
checked={stickyModesEnabled}
36+
onChange={(e: any) => setCachedStateField("stickyModesEnabled", e.target.checked)}
37+
data-testid="sticky-modes-enabled-checkbox">
38+
<span className="font-medium">{t("settings:miscellaneous.stickyModes.label")}</span>
39+
</VSCodeCheckbox>
40+
<div className="text-vscode-descriptionForeground text-sm mt-1">
41+
{t("settings:miscellaneous.stickyModes.description")}
42+
</div>
43+
</div>
44+
</Section>
45+
</div>
46+
)
47+
}

webview-ui/src/components/settings/SettingsView.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Bell,
99
Database,
1010
SquareTerminal,
11+
Settings as SettingsIcon, // renamed to avoid conflict with component name
1112
FlaskConical,
1213
AlertTriangle,
1314
Globe,
@@ -49,6 +50,7 @@ import { CheckpointSettings } from "./CheckpointSettings"
4950
import { NotificationSettings } from "./NotificationSettings"
5051
import { ContextManagementSettings } from "./ContextManagementSettings"
5152
import { TerminalSettings } from "./TerminalSettings"
53+
import { MiscellaneousSettings } from "./MiscellaneousSettings"
5254
import { ExperimentalSettings } from "./ExperimentalSettings"
5355
import { LanguageSettings } from "./LanguageSettings"
5456
import { About } from "./About"
@@ -66,6 +68,7 @@ const sectionNames = [
6668
"notifications",
6769
"contextManagement",
6870
"terminal",
71+
"miscellaneous",
6972
"experimental",
7073
"language",
7174
"about",
@@ -131,6 +134,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
131134
terminalZshOhMy,
132135
terminalZshP10k,
133136
terminalZdotdir,
137+
stickyModesEnabled,
134138
writeDelayMs,
135139
showRooIgnoredFiles,
136140
remoteBrowserEnabled,
@@ -244,6 +248,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
244248
vscode.postMessage({ type: "terminalZshOhMy", bool: terminalZshOhMy })
245249
vscode.postMessage({ type: "terminalZshP10k", bool: terminalZshP10k })
246250
vscode.postMessage({ type: "terminalZdotdir", bool: terminalZdotdir })
251+
vscode.postMessage({ type: "stickyModesEnabled", bool: stickyModesEnabled })
247252
vscode.postMessage({ type: "mcpEnabled", bool: mcpEnabled })
248253
vscode.postMessage({ type: "alwaysApproveResubmit", bool: alwaysApproveResubmit })
249254
vscode.postMessage({ type: "requestDelaySeconds", value: requestDelaySeconds })
@@ -288,6 +293,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
288293
const notificationsRef = useRef<HTMLDivElement>(null)
289294
const contextManagementRef = useRef<HTMLDivElement>(null)
290295
const terminalRef = useRef<HTMLDivElement>(null)
296+
const miscellaneousRef = useRef<HTMLDivElement>(null)
291297
const experimentalRef = useRef<HTMLDivElement>(null)
292298
const languageRef = useRef<HTMLDivElement>(null)
293299
const aboutRef = useRef<HTMLDivElement>(null)
@@ -301,6 +307,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
301307
{ id: "notifications", icon: Bell, ref: notificationsRef },
302308
{ id: "contextManagement", icon: Database, ref: contextManagementRef },
303309
{ id: "terminal", icon: SquareTerminal, ref: terminalRef },
310+
{ id: "miscellaneous", icon: SettingsIcon, ref: miscellaneousRef },
304311
{ id: "experimental", icon: FlaskConical, ref: experimentalRef },
305312
{ id: "language", icon: Globe, ref: languageRef },
306313
{ id: "about", icon: Info, ref: aboutRef },
@@ -313,6 +320,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
313320
notificationsRef,
314321
contextManagementRef,
315322
terminalRef,
323+
miscellaneousRef,
316324
experimentalRef,
317325
],
318326
)
@@ -494,6 +502,13 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
494502
/>
495503
</div>
496504

505+
<div ref={miscellaneousRef}>
506+
<MiscellaneousSettings
507+
stickyModesEnabled={stickyModesEnabled}
508+
setCachedStateField={setCachedStateField}
509+
/>
510+
</div>
511+
497512
<div ref={experimentalRef}>
498513
<ExperimentalSettings
499514
setCachedStateField={setCachedStateField}

webview-ui/src/context/ExtensionStateContext.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ export interface ExtensionStateContextType extends ExtensionState {
8787
pinnedApiConfigs?: Record<string, boolean>
8888
setPinnedApiConfigs: (value: Record<string, boolean>) => void
8989
togglePinnedApiConfig: (configName: string) => void
90+
stickyModesEnabled: boolean
91+
setStickyModesEnabled: (value: boolean) => void
9092
}
9193

9294
export const ExtensionStateContext = createContext<ExtensionStateContextType | undefined>(undefined)
@@ -163,6 +165,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
163165
terminalZshOhMy: false, // Default Oh My Zsh integration setting
164166
terminalZshP10k: false, // Default Powerlevel10k integration setting
165167
terminalZdotdir: false, // Default ZDOTDIR handling setting
168+
stickyModesEnabled: true, // Default sticky modes to enabled
166169
})
167170

168171
const [didHydrateState, setDidHydrateState] = useState(false)
@@ -331,6 +334,8 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
331334

332335
return { ...prevState, pinnedApiConfigs: newPinned }
333336
}),
337+
stickyModesEnabled: state.stickyModesEnabled ?? true,
338+
setStickyModesEnabled: (value) => setState((prevState) => ({ ...prevState, stickyModesEnabled: value })),
334339
}
335340

336341
return <ExtensionStateContext.Provider value={contextValue}>{children}</ExtensionStateContext.Provider>

0 commit comments

Comments
 (0)