diff --git a/src/ui.tsx b/src/ui.tsx index 4b0ca92..84b1f89 100644 --- a/src/ui.tsx +++ b/src/ui.tsx @@ -196,17 +196,29 @@ function Plugin () { }, []) function toggleWindowSize () { - // "Maximize" targets the visible viewport geometry (maxViewport = bounds*zoom, - // without subtracting header/frame). Figma clamps the request to its real window - // limit (depends on whether Figma UI is hidden). The real size is then measured - // via the iframe (window.innerWidth/Height) and shown as lastSize/gaps. const max = windowInfo != null ? windowInfo.maxViewport : { width: 1920, height: 1080 } const isMaximized = currentWindowSize.width >= max.width && currentWindowSize.height >= max.height - const next = isMaximized ? { ...MIN_WINDOW_SIZE } : { ...max } - setCurrentWindowSize(next) - emit('RESIZE_WINDOW', next) - refreshInfo() + if (!isMaximized) { + // Maximize: stretch to the full available viewport, then pin to center-top. + setCurrentWindowSize({ ...max }) + emit('RESIZE_WINDOW', { ...max }) + // After Figma applies the resize (and clamps to its real limit), reposition to + // center-top from the REAL rendered size (read from the iframe). + requestAnimationFrame(function () { + requestAnimationFrame(function () { + emit('DOCK_REFINE', { + position: 'top-center', + width: window.innerWidth, + height: window.innerHeight + }) + refreshInfo() + }) + }) + } else { + // Restore: behave exactly like the Center button (50% viewport, centered). + dockWindow('center') + } } // 9 dock positions: 4 corners + 4 edges + center.