diff --git a/webview-ui/src/components/common/Tab.tsx b/webview-ui/src/components/common/Tab.tsx index 99c2b7b4b0..495bb1b34b 100644 --- a/webview-ui/src/components/common/Tab.tsx +++ b/webview-ui/src/components/common/Tab.tsx @@ -17,7 +17,7 @@ export const TabHeader = ({ className, children, ...props }: TabProps) => ( ) -export const TabContent = ({ className, children, ...props }: TabProps) => { +export const TabContent = forwardRef(({ className, children, ...props }, ref) => { const { renderContext } = useExtensionState() const onWheel = useCallback( @@ -40,11 +40,12 @@ export const TabContent = ({ className, children, ...props }: TabProps) => { ) return ( -
+
{children}
) -} +}) +TabContent.displayName = "TabContent" export const TabList = forwardRef< HTMLDivElement, diff --git a/webview-ui/src/components/settings/SettingsView.tsx b/webview-ui/src/components/settings/SettingsView.tsx index f680f3e5fe..632873308e 100644 --- a/webview-ui/src/components/settings/SettingsView.tsx +++ b/webview-ui/src/components/settings/SettingsView.tsx @@ -112,6 +112,11 @@ const SettingsView = forwardRef(({ onDone, t : "providers", ) + const scrollPositions = useRef>( + Object.fromEntries(sectionNames.map((s) => [s, 0])) as Record, + ) + const contentRef = useRef(null) + const prevApiConfigName = useRef(currentApiConfigName) const confirmDialogHandler = useRef<() => void>() @@ -398,12 +403,20 @@ const SettingsView = forwardRef(({ onDone, t // Handle tab changes with unsaved changes check const handleTabChange = useCallback( (newTab: SectionName) => { - // Directly switch tab without checking for unsaved changes + if (contentRef.current) { + scrollPositions.current[activeTab] = contentRef.current.scrollTop + } setActiveTab(newTab) }, - [], // No dependency on isChangeDetected needed anymore + [activeTab], ) + useLayoutEffect(() => { + if (contentRef.current) { + contentRef.current.scrollTop = scrollPositions.current[activeTab] ?? 0 + } + }, [activeTab]) + // Store direct DOM element refs for each tab const tabRefs = useRef>( Object.fromEntries(sectionNames.map((name) => [name, null])) as Record, @@ -579,7 +592,7 @@ const SettingsView = forwardRef(({ onDone, t {/* Content area */} - + {/* Providers Section */} {activeTab === "providers" && (