fix(muya): keep an image resize released outside the window (#5393) by Jocs · Pull Request #5537 · marktext/marktext · GitHub
Skip to content

fix(muya): keep an image resize released outside the window (#5393) - #5537

Merged
Jocs merged 1 commit into
developfrom
fix/image-resize-released-outside-window-5393
Sep 23, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/image-resize-released-outside-window-5393

Conversation

@Jocs

@Jocs Jocs commented Sep 23, 2026

Copy link
Copy Markdown
Member

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 ![](pic.png) 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 where ImageResizeBar attached the drag's mousemove and mouseup listeners. _mouseUp therefore never ran, so updateImage was never called. Chromium then delivers a click on the press/release common ancestor (again <html>), which the bar hides on, and hide() 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:

BODY:mousedown target=#handle x=110 y=125     <- body listener fires
BODY:mousemove target=BODY   x=300 y=125      <- inside the window: fires
DOC :mousemove target=HTML   x=780 y=125      <- outside: body listener silent
DOC :mouseup   target=HTML   x=780 y=125      <- _mouseUp never runs
DOC :click     target=HTML   x=780 y=125      <- hide() -> _width = null

Fix

Attach the drag's mousemove/mouseup to document instead of document.body, so the listeners sit above the <html> target. tableDragBar, paragraphFrontButton and TableRectSelection already attach their drag listeners this way — imageResizeBar was the only one on document.body. The mousedown listener stays on document.body; the handles always live there.

Tests

  • packages/muya/src/ui/imageResizeBar/__tests__/imageResizeBar.spec.ts — a drag whose moves and release are dispatched on document.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 on develop with updateImage never 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 was HTML before asserting the markdown gained a width, so a clamped or shortened drag cannot leave the regression uncovered.
  • Two existing assertions in the unit spec keyed on e.target === document.body were narrowed to e.event === 'mousemove'; with the drag listeners on document they 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:

release target <img> on screen file after Save
before HTML @ clientX=870 464 px ![](pic.png)
after HTML @ clientX=870 width committed <img src="pic.png" … width="599" />

🤖 Generated with Claude Code

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>
@Jocs
Jocs merged commit ccc6b05 into develop Sep 23, 2026
7 checks passed
@Jocs
Jocs deleted the fix/image-resize-released-outside-window-5393 branch September 23, 2026 14:41
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.

[Bug] Image resize is silently discarded when the mouse button is released outside the window

1 participant