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