{{ message }}
Repository navigation
feat(muya): emit format-click and preview-image interaction events - #4390
Merged
Merged
Conversation
Desktop is migrating off legacy packages/muyajs to packages/muya
(@muyajs/core). The legacy engine emitted custom interaction events that
the desktop renderer's editor.vue subscribes to in order to open links and
preview images on a Cmd/Ctrl-click. packages/muya had no such emitter, so
port the link + image format-click events:
- editor/linkMouseEvents.ts: on a Cmd/Ctrl-click of a rendered link, emit
`format-click` with { event, formatType: 'link', data } where data is the
getLinkInfo payload (superset of the legacy { text, href }). Plain clicks
keep their cursor-placement-only behavior (preventDefault unchanged).
- selection/index.ts (_handleClickInlineImage): on a Cmd/Ctrl-click of an
<img>, emit `format-click` with { event, formatType: 'image', data: <src> }
(src resolved via getImageSrc, falling back to the <img> src attribute).
The plain-click image-toolbar / transformer / selector path is untouched.
The desktop's format-click handler re-checks the OS modifier and opens the
link / SimpleImageViewer, so muya stays platform-agnostic and only emits.
heading-copy-link is deferred: it needs new heading-hover UI that does not
exist in packages/muya yet.
Adds a happy-dom vitest spec that subscribes via muya.on('format-click')
and simulates modifier-clicks on a rendered link and image, asserting the
payload shape and that plain clicks do not emit.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR restores legacy interaction behavior during the ongoing migration from packages/muyajs to packages/muya by emitting desktop-consumed click events for Cmd/Ctrl-clicks on rendered links and inline images.
Changes:
- Emit
format-clickfor Cmd/Ctrl-clicked links fromeditor/linkMouseEvents.tswith agetLinkInfo()-based payload. - Emit
format-clickfor Cmd/Ctrl-clicked inline images fromselection/index.ts, resolving the imagesrcviagetImageSrc()with an attribute fallback. - Add a Vitest (happy-dom) spec to ensure modifier-clicks emit and plain clicks do not.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+118
to
+132
Member
Author
There was a problem hiding this comment.
Added in dbbcff5 — there's now an explicit image Ctrl-click test (dispatchClick(img, { ctrlKey: true })) asserting the same payload, mirroring the existing link Ctrl-click case. Both modifier paths are now covered.
Address Copilot review: the image format-click tests only exercised the macOS metaKey modifier, but the handler emits on (metaKey || ctrlKey). Add a Ctrl-click case for the image path, mirroring the existing link Ctrl-click test. Co-Authored-By: Claude Opus 4.8 (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.

Motivation
The desktop app is migrating off the legacy
packages/muyajsengine topackages/muya(@muyajs/core). The legacy engine emitted custom interaction events that the desktop renderer (packages/desktop/src/renderer/src/components/editorWithTabs/editor.vue) subscribes to so a Cmd/Ctrl-click can open a link or preview an image.packages/muyarendered links/images but had no emitter for these events, so the migration would silently lose link-open and image-preview-on-click.This PR ports the two click events the desktop consumes. (The related
selection-changecursorCoords/formatswork is already merged; this PR is only the click events.)Events + payloads
Ported faithfully from the legacy engine (
packages/muyajs/lib/contentState/clickCtrl.jslink path +packages/muyajs/lib/eventHandler/clickEvent.jsimage path):format-click(link) —editor/linkMouseEvents.ts. On a Cmd/Ctrl-click of a rendered link, emits{ event, formatType: 'link', data }wheredatais thegetLinkInfopayload ({ href, raw, text, range }, a superset of the legacy{ text, href }). Plain (no-modifier) clicks keep their existing cursor-placement-only behavior — thepreventDefault()on anchors is unchanged.format-click(image) —selection/index.ts(_handleClickInlineImage). On a Cmd/Ctrl-click of an<img>, emits{ event, formatType: 'image', data: <src> }. The src is resolved viagetImageSrc(token.src || token.attrs.src)(the same path-resolution the renderer uses), falling back to the rendered<img>'s ownsrcattribute. The plain-click image-toolbar / transformer / selector / resize path is untouched.The desktop's
format-clickhandler re-checks the OS modifier and opens the link (FORMAT_LINK_CLICK) or aSimpleImageViewer, so muya stays platform-agnostic and only emits.Both checks gate on the modifier in muya so plain clicks are unaffected.
packages/muya/src/muya.tswas intentionally not touched.Deferred
heading-copy-linkis not implemented here. It requires new heading-hover UI that does not yet exist inpackages/muya(legacy fired it from a.ag-copy-header-linkbutton that the new renderer has no equivalent for). Out of scope for this PR.preview-imageis not emitted from the click path: in the legacy engine it fired only from the Space-key handler (keyboard.js), not on click, and on the desktop side it does the same thing as the imageformat-click(opens the viewer). Emitting it on a modifier-click too would open the viewer twice, so the click path uses the imageformat-clickonly — matching legacy.Tests
Adds
packages/muya/src/__tests__/formatClickEvents.spec.ts(happy-dom, follows thegetTOC.spec.tsboot pattern). It subscribes viamuya.on('format-click', ...)and simulates modifier-clicks on a rendered link and image, asserting the payload shape, the macOS (metaKey) and non-macOS (ctrlKey) variants, and that plain clicks do not emit.Verify
All green in
packages/muya:pnpm -C packages/muya lint— 0 errors (pre-existing complexity warnings only, none in changed files)pnpm -C packages/muya lint:types— passespnpm -C packages/muya check-circular— no circular dependencypnpm -C packages/muya test— 417 passed (51 files; +5 new)pnpm -C packages/muya test:spec— 1347 passed🤖 Generated with Claude Code