diff --git a/js/components/WindowManager.js b/js/components/WindowManager.js index a31e5816..b5a91cad 100644 --- a/js/components/WindowManager.js +++ b/js/components/WindowManager.js @@ -64,12 +64,15 @@ class WindowManager extends React.Component { const boxWidth = bounding.right - bounding.left; const move = { - x: Math.ceil(offsetLeft + (width - boxWidth) / 2), - y: Math.ceil(offsetTop + (height - boxHeight) / 2) + x: Math.ceil(offsetLeft - bounding.left + (width - boxWidth) / 2), + y: Math.ceil(offsetTop - bounding.top + (height - boxHeight) / 2) }; const newPositions = this.props.windowsInfo.reduce( - (pos, w) => ({ ...pos, [w.key]: { x: move.x + w.x, y: move.y + w.y } }), + (pos, w) => ({ + ...pos, + [w.key]: { x: move.x + w.x, y: move.y + w.y } + }), {} ); diff --git a/js/utils.ts b/js/utils.ts index bebf80b5..5c2a4ef5 100644 --- a/js/utils.ts +++ b/js/utils.ts @@ -328,15 +328,19 @@ interface Window { } export const calculateBoundingBox = (windows: Window[]) => - windows.reduce( - (b, w) => ({ - left: Math.min(b.left, w.x), - top: Math.min(b.top, w.y), - bottom: Math.max(b.bottom, w.y + w.height), - right: Math.max(b.right, w.x + w.width) - }), - { top: 0, bottom: 0, left: 0, right: 0 } - ); + windows + .map(w => ({ + left: w.x, + top: w.y, + bottom: w.y + w.height, + right: w.x + w.width + })) + .reduce((b, w) => ({ + left: Math.min(b.left, w.left), + top: Math.min(b.top, w.top), + bottom: Math.max(b.bottom, w.bottom), + right: Math.max(b.right, w.right) + })); export function findLastIndex(arr: T[], cb: (val: T) => boolean) { for (let i = arr.length - 1; i >= 0; i--) {