{{ message }}
Repository navigation
fix(muya): keep an image resize released outside the window (#5393) - #5537
Merged
Merged
Conversation
A pointer dragged past the window's edge keeps driving the resize, but Chromium hit tests those out-of-viewport coordinates to `<html>`, whose bubble path is html -> document -> window and never passes through `<body>` — where the drag's mousemove and mouseup listeners were attached. The release therefore never reached `_mouseUp`, and the click Chromium delivers afterwards (also on `<html>`) hid the bar and cleared the pending width. The image kept the size it had been dragged to on screen while the document was left unmodified, so Save wrote the original size back. Attach the drag listeners to the document, as `tableDragBar`, `paragraphFrontButton` and `TableRectSelection` already do. Co-Authored-By: Claude Opus 5 (1M context) <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.

Closes #5393.
Problem
Dragging an image's resize handle and releasing the mouse button outside the MarkText window discarded the resize. The image kept the new size on screen, but the document was never marked modified, Save wrote the line back as
with no width, and reopening the file showed the original size.Root cause
A pointer dragged past the window's edge keeps driving the resize — the browser holds the pointer while a button is down — but Chromium hit tests those out-of-viewport coordinates to
<html>.<html>is not inside<body>, so the event's bubble path is html → document → window and skips<body>entirely, which is whereImageResizeBarattached the drag'smousemoveandmouseuplisteners._mouseUptherefore never ran, soupdateImagewas never called. Chromium then delivers aclickon the press/release common ancestor (again<html>), which the bar hides on, andhide()clears the pending_width(#5288) — the width the drag had written straight onto the<img>element stayed on screen with nothing behind it.Verified with OS-level mouse input (CGEvents) against a real Chromium window:
Fix
Attach the drag's
mousemove/mouseuptodocumentinstead ofdocument.body, so the listeners sit above the<html>target.tableDragBar,paragraphFrontButtonandTableRectSelectionalready attach their drag listeners this way —imageResizeBarwas the only one ondocument.body. Themousedownlistener stays ondocument.body; the handles always live there.Tests
packages/muya/src/ui/imageResizeBar/__tests__/imageResizeBar.spec.ts— a drag whose moves and release are dispatched ondocument.documentElement(followed by the click Chromium delivers on<html>) must still commit the width, and must leave no drag listeners behind. The first test fails ondevelopwithupdateImagenever called.packages/muya/e2e/tests/drag/image-resize-outside-window-5393.spec.ts— a real Chromium drag released past the viewport's right edge. It asserts the release target really wasHTMLbefore asserting the markdown gained awidth, so a clamped or shortened drag cannot leave the regression uncovered.e.target === document.bodywere narrowed toe.event === 'mousemove'; with the drag listeners ondocumentthey would otherwise have passed vacuously.Also verified end to end in the built app with real OS-level mouse input, dragging a handle out through the window edge and releasing there:
<img>on screenHTML@ clientX=870HTML@ clientX=870<img src="pic.png" … width="599" />🤖 Generated with Claude Code