fix: maximize/restore toggles via explicit flag (was stuck due to Figma size clamp)

This commit is contained in:
Hermes Agent committed 2026-09-11 13:24:34 +02:00
1 parent 534149991e
commit fda4be1765
1 file changed
+13 -13
+13 -13
View File
@@ -26,6 +26,9 @@ function Plugin () {
const dockedPosRef = useRef<DockPosition | null>(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 (
<Fragment>