Skip to content

Fix: enforce viewport boundaries during window resize - #401

Merged
AllTerrainDeveloper merged 3 commits into
WordPress:trunkfrom
CookieDarb:fix/window-resize-boundary
Jul 23, 2026
Merged

Fix: enforce viewport boundaries during window resize#401
AllTerrainDeveloper merged 3 commits into
WordPress:trunkfrom
CookieDarb:fix/window-resize-boundary

Conversation

@CookieDarb

Copy link
Copy Markdown
Contributor

What?

Closes #399

Enforces viewport boundaries during window resize to prevent the title bar from going off-screen.

Why?

Previously, dragging the top handles past the physical edges of the desktop allowed the math to compute negative coordinates for the window. This pushed the window's title bar off-screen, rendering the window permanently unreachable and unmovable without refreshing the page.

How?

  • src/window/pointer.ts:
    • Added clamping logic at the end of computeResize to ensure x and y never fall below EDGE_MARGIN (0).
    • Dynamically reduces the resulting width and height by the clamped difference so the opposite pinned edges remain perfectly locked in place despite the clamp.
  • tests/vitest/window-resize.test.ts:
    • Updated expected geometry math for NE, SW, and NW corner drag tests.
    • Added a dedicated test asserting bounds clamping remains strictly enforced when the drag delta extends far past the desktop boundary.

Testing Instructions

  1. Open any window in the desktop mode environment.
  2. Grab the top-right or top-left corner of the window.
  3. Drag your mouse aggressively upwards, pushing past the top of the desktop screen.
  4. Release the mouse.
  5. Verify that the window's top edge (title bar) is stopped flush at the top boundary (y=0) and remains fully reachable.
  6. Repeat the process dragging the left edge past the left side of the screen.

Screencast

Screen.Recording.2026-07-23.at.8.31.13.PM.mov

@CookieDarb
CookieDarb marked this pull request as ready for review July 23, 2026 15:11
@AllTerrainDeveloper

Copy link
Copy Markdown
Collaborator

Ouch, I haven't seen this PR and already merged a similar one, but Ill also merge this one as it adds value with the tests. Thank you!

AllTerrainDeveloper and others added 2 commits July 23, 2026 20:20
Trunk picked up two fixes for the same bug (WordPress#399): WordPress#402 clamped the
window position in onResizeMove after the math ran, and this PR clamps
inside computeResize while shrinking the dimension by the clamped
difference. The handler-side clamp is strictly worse once both exist:
clamping y without compensating height lets the pinned bottom edge
slide down while the user drags the top handle, and its Math.min
against the desktop's right/bottom shifts the whole window during a
plain SE grow — stricter than what drag itself enforces. Keep the
pure-math clamp (which the vitest suite covers directly) and remove
the handler block.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WCknM6zk6JS14pdLUiqdRR
@AllTerrainDeveloper

Copy link
Copy Markdown
Collaborator

Sorry for jumping in and pushing to your branch directly — I took the opportunity to combine the two fixes. Since #402 was already merged, I brought trunk in and kept your computeResize clamp (it keeps the opposite edge pinned and is unit-tested), removing the now-redundant handler-side clamp from #402.

Thank you for the great fix and especially for the tests — much appreciated! 🙏

@AllTerrainDeveloper
AllTerrainDeveloper merged commit e3265b4 into WordPress:trunk Jul 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Window title bar can be pushed off-screen when resizing upwards

2 participants