Describe the bug
Note
This report comes from an analysis of the code, not from a reproduction. The behaviour described below has not been observed in maxGraph yet and must be verified first. It is expected to occur, since maxGraph has the same code as mxGraph here, and draw.io changed that code to fix it.
When the mouse button is released outside the browser window during a pan, maxGraph probably misses the release:
- Panning stays engaged.
PanningHandler stops panning on a mouseup listener registered on document (PanningHandler.ts#L118-L125). A release outside the window does not reach that listener, so when the mouse comes back, the graph may keep panning although no button is pressed.
- The graph keeps believing the button is down.
graph.isMouseDown is only reset when the graph itself receives the mouseup (EventsMixin.ts#L502-L503), and PanningHandler.reset() does not touch it (PanningHandler.ts#L438-L444). While it stays true, isEventIgnored drops the next mousedown as out of sequence (EventsMixin.ts#L508-L520), and mouse moves trigger the auto scroll reserved for drags (EventsMixin.ts#L680-L686).
Both points are inferred from reading the code. Their visible effect, and whether a later event resynchronises the state, are part of what the verification has to establish.
To Reproduce
Not reproduced yet. Suggested steps to verify:
- Open a story with panning enabled, for instance any story calling
graph.setPanning(true).
- Start panning with the mouse (right button, or as configured), move the pointer out of the browser window, and release the button there.
- Move the pointer back over the graph without pressing any button: check whether the graph still pans.
- Click a cell: check whether the click is taken into account or ignored.
Expected behavior
Releasing the button outside the window ends the pan, and the graph no longer considers the button pressed.
mxGraph behaves like maxGraph here: it only listens to mouseup on document (mxPanningHandler.js#L98-L99) and its reset() does not touch isMouseDown. So if the bug exists, it also existed in mxGraph.
draw.io, where jgraph kept developing mxGraph after the archival of jgraph/mxgraph, fixed it with two changes that work together. They first shipped in release 14.1.3 (commit 16d9dab274eb440926def4d53b9e7d4d52b7763a, 2020-12-28), and are still present today (mxPanningHandler.js at the current dev branch):
-
the release listener also fires when the mouse leaves the window, and covers touch and pointer releases (L98-L101, removed accordingly in destroy at L497-L498):
mxEvent.addGestureListeners(document, null, null, this.mouseUpListener);
mxEvent.addListener(document, 'mouseleave', this.mouseUpListener);
-
reset(), which that listener calls, also resets the mouse state of the graph (L469):
this.graph.isMouseDown = false
maxGraph already provides InternalEvent.addGestureListeners and removeGestureListeners, so porting the fix would be a few lines in PanningHandler, plus tests.
Environment
maxGraph version or commit: all versions up to 0.25.1, code still present on main at 6df0cfd
- Desktop or mobile: desktop expected, touch not analysed
- Browser and version: not verified
Additional context
The gap was found while setting up the mxgraph-archaeologist agent of the repository (#1302), during one of its validation runs comparing PanningHandler with its mxGraph original and its current draw.io version.
Until release 22.0.0, the draw.io repository held no mxGraph source code, only the minified mxGraph bundle mxClient.js. The fix therefore first appears there in minified form, in 14.1.3. The mxGraph source code was first published in 22.0.0 (commit 8906f90ac0cc50a0c6da77c28cf9b2b2339277b1, 2023-09-28), with the fix already in (mxPanningHandler.js#L100-L101 and L469). No public commit shows the change as a readable diff.