From b63cec5cbd9fd92cec32bb81132a00f005400bc4 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Sun, 29 Jun 2025 17:25:37 -0700 Subject: [PATCH] Fix recentering bug --- packages/webamp/CHANGELOG.md | 4 ++++ packages/webamp/js/actionCreators/windows.ts | 16 +++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/webamp/CHANGELOG.md b/packages/webamp/CHANGELOG.md index 184ce5ef..a36d970f 100644 --- a/packages/webamp/CHANGELOG.md +++ b/packages/webamp/CHANGELOG.md @@ -12,6 +12,10 @@ - Add new config option `enableMediaSession` to allow Webamp to connect to the browser's Media Session API. This enables OS/hardware level media controls like play/pause/next/previous. - Ensure the promise returned from `renderWhenReady` only resolves after the Webamp instance has been fully mounted and inserted into the DOM. Previously it resolved after the DOM node was created but before it was inserted into the DOM. +### Bug Fixes + +- Fix bug where resizing the window such that the current layout cannot fit on the page, while also scrolled down the page, would cause the layout to be recentered out of view. + ## 2.1.2 [CURRENT] ### Bug Fixes diff --git a/packages/webamp/js/actionCreators/windows.ts b/packages/webamp/js/actionCreators/windows.ts index 9b199fbd..dfee7f72 100644 --- a/packages/webamp/js/actionCreators/windows.ts +++ b/packages/webamp/js/actionCreators/windows.ts @@ -128,25 +128,23 @@ export function centerWindowsInContainer(container: HTMLElement): Thunk { } export function centerWindowsInView(): Thunk { - return centerWindows({ - left: window.scrollX, - top: window.scrollY, - width: window.innerWidth, - height: window.innerHeight, - }); + const height = window.innerHeight; + const width = window.innerWidth; + return centerWindows({ left: 0, top: 0, width, height }); } -export function centerWindows(box: { +type Box = { left: number; top: number; width: number; height: number; -}): Thunk { +}; + +export function centerWindows({ left, top, width, height }: Box): Thunk { return (dispatch, getState) => { const state = getState(); const windowsInfo = Selectors.getWindowsInfo(state); const getOpen = Selectors.getWindowOpen(state); - const { top, left, width, height } = box; const offsetLeft = left + window.scrollX; const offsetTop = top + window.scrollY;