Fix stuck pan when middle-button release lands on toolbar overlay#94
Merged
Conversation
Middle-drag pan continued tracking the cursor until the user clicked again if the release happened over the floating top toolbar. The dual- path pan architecture (Pixi pointermove inside the viewport, window mousemove outside) meant neither handler could see the release once the cursor was over an overlay element, and neither validated that any button was still held. Collapse pan to a single window-level pointer event listener. Switch from mouse events to pointer events because Chromium fires only pointer events for CDP-driven middle-button gestures (verified via browser console diagnostic). Add a buttons === 0 recovery check so a missed pointerup self-heals on the next move. Net diff is -36 lines: removed handleStagePointerMove from the viewport hook, the handleScenePointerMove plumbing through stageHandlers and CanvasStage, the isClientPointInsideViewport early-return, and the isPanDragging state. Added a PointerEvent polyfill for jsdom and fixed the synthetic test API to track pressedButton through middle-button pan starts. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Middle-drag pan was sticking to the cursor (with no buttons held) when the user released the middle mouse button while hovering over the floating top toolbar — pan only stopped on the next click anywhere.
Root cause
Two compounding issues:
pointermovedrove pan when the cursor was inside the canvas; a windowmousemovelistener drove it when outside. The toolbar overlays the canvas, so neither handler could see the release once the cursor was over a toolbar element.panDragRefwas set, any future move kept panning.What changed
pointermove/pointerup/pointercancel).event.buttons === 0recovery so a missedpointerupself-heals on the next move.isClientPointInsideViewportearly-return, theisPanDraggingstate, and thehandleScenePointerMoveplumbing throughstageHandlersandCanvasStage— all dead after the collapse.Net diff: -36 lines across 7 files.
TDD
Added a red-first jsdom test: while pan is active, dispatch a window pointermove with
buttons: 0and assert the pan was cleared. Verified failing before the fix, passing after.Existing pan tests adapted to dispatch
PointerEventwithbuttonsset (aPointerEventpolyfill was added insrc/test/setup.tssince jsdom doesn't ship one). The synthetic test API incanvasTestApi.tsnow trackspressedButtonthrough middle-button-onlystartPanDragpaths so subsequentpointermovedispatches reportbuttons=4instead of0.Test plan
npm run preflight(lint + typecheck + unit + e2e)No Playwright e2e for the regression itself: headless Chromium on Linux/macOS doesn't reproduce the Windows middle-button trigger that surfaces the bug, so a passing e2e would be misleading coverage.
🤖 Generated with Claude Code