From fda4be1765c22c238f3dae20c285d0023d84413c Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Fri, 11 Sep 2026 13:24:34 +0200 Subject: [PATCH] fix: maximize/restore toggles via explicit flag (was stuck due to Figma size clamp) --- src/ui.tsx | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/ui.tsx b/src/ui.tsx index 84b1f89..cd43bd3 100644 --- a/src/ui.tsx +++ b/src/ui.tsx @@ -26,6 +26,9 @@ function Plugin () { const dockedPosRef = useRef(null) // Flag: resize pulls the window out of dock (on release, do not re-dock, clear dock state). const exitingDockRef = useRef(false) + // Explicit toggle state for the Maximize/Restore button (size comparison is unreliable + // because Figma clamps the requested size to its real limit when its UI is visible). + const maximizedRef = useRef(false) const [windowInfo, setWindowInfo] = useState<{ x: number; y: number; width: number; height: number zoom: number @@ -196,11 +199,11 @@ function Plugin () { }, []) function toggleWindowSize () { - const max = windowInfo != null ? windowInfo.maxViewport : { width: 1920, height: 1080 } - const isMaximized = - currentWindowSize.width >= max.width && currentWindowSize.height >= max.height - if (!isMaximized) { + if (!maximizedRef.current) { // Maximize: stretch to the full available viewport, then pin to center-top. + maximizedRef.current = true + setIsMaxToggled(true) + const max = windowInfo != null ? windowInfo.maxViewport : { width: 1920, height: 1080 } setCurrentWindowSize({ ...max }) emit('RESIZE_WINDOW', { ...max }) // After Figma applies the resize (and clamps to its real limit), reposition to @@ -217,6 +220,8 @@ function Plugin () { }) } else { // Restore: behave exactly like the Center button (50% viewport, centered). + maximizedRef.current = false + setIsMaxToggled(false) dockWindow('center') } } @@ -256,15 +261,10 @@ function Plugin () { }) } - const max = windowInfo != null ? windowInfo.maxViewport : null - // "Maximized" if the window reached (or exceeded) the viewport geometry - // (maxViewport = bounds*zoom). Figma clamps the request to its limit, so the real - // lastSize may be slightly less than maxViewport — at the ceiling currentWindowSize - // will be >= maxViewport and the icon will show "restore". - const isMaximized = - max != null && - currentWindowSize.width >= max.width && - currentWindowSize.height >= max.height + const [isMaxToggled, setIsMaxToggled] = useState(false) + // "Maximized" flag drives the icon (expand/collapse). Real size after maximize is + // clamped by Figma, so we track it explicitly rather than comparing sizes. + const isMaximized = isMaxToggled return (