From 8ac0a27f33b2f248a0d2f6c4b9badd58a93916a7 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Wed, 19 Nov 2025 22:19:36 -0800 Subject: [PATCH] fix drag to collapse sidebar --- .../layouts/default-layout/main-content.tsx | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/renderer/layouts/default-layout/main-content.tsx b/src/renderer/layouts/default-layout/main-content.tsx index c683f3a7f..9728756ef 100644 --- a/src/renderer/layouts/default-layout/main-content.tsx +++ b/src/renderer/layouts/default-layout/main-content.tsx @@ -35,6 +35,7 @@ export const MainContent = ({ shell }: { shell?: boolean }) => { const mainContentRef = useRef(null); const initialRightWidthRef = useRef(rightWidth); const initialMouseXRef = useRef(0); + const wasCollapsedDuringDragRef = useRef(false); useEffect(() => { if (mainContentRef.current && !isResizing && !isResizingRight) { @@ -48,6 +49,7 @@ export const MainContent = ({ shell }: { shell?: boolean }) => { (position: 'left' | 'right', mouseEvent?: MouseEvent) => { if (position === 'left') { setIsResizing(true); + wasCollapsedDuringDragRef.current = false; } else { setIsResizingRight(true); if (mainContentRef.current && rightSidebarRef.current && mouseEvent) { @@ -69,11 +71,14 @@ export const MainContent = ({ shell }: { shell?: boolean }) => { const stopResizing = useCallback(() => { if (isResizing && mainContentRef.current) { - const finalWidth = mainContentRef.current.style.getPropertyValue('--sidebar-width'); - if (finalWidth) { - setSideBar({ collapsed: false, leftWidth: finalWidth }); + if (!wasCollapsedDuringDragRef.current) { + const finalWidth = mainContentRef.current.style.getPropertyValue('--sidebar-width'); + if (finalWidth) { + setSideBar({ collapsed: false, leftWidth: finalWidth }); + } } setIsResizing(false); + wasCollapsedDuringDragRef.current = false; } else if (isResizingRight && mainContentRef.current) { const finalWidth = mainContentRef.current.style.getPropertyValue('--right-sidebar-width'); @@ -90,11 +95,19 @@ export const MainContent = ({ shell }: { shell?: boolean }) => { if (isResizing) { const width = mouseMoveEvent.clientX; - const constrainedWidth = `${constrainSidebarWidth(width)}px`; + const constrainedWidthValue = constrainSidebarWidth(width); + const constrainedWidth = `${constrainedWidthValue}px`; if (width < MINIMUM_SIDEBAR_WIDTH - 100) { - setSideBar({ collapsed: true }); + if (!wasCollapsedDuringDragRef.current) { + wasCollapsedDuringDragRef.current = true; + setSideBar({ collapsed: true }); + } } else { + if (wasCollapsedDuringDragRef.current) { + wasCollapsedDuringDragRef.current = false; + setSideBar({ collapsed: false }); + } mainContentRef.current.style.setProperty('--sidebar-width', constrainedWidth); } } else if (isResizingRight) {