Tiptap: Preserve wrapping link when editing an image (closes #23013)#23019
Tiptap: Preserve wrapping link when editing an image (closes #23013)#23019AndyButland wants to merge 2 commits into
Conversation
|
Claude finished @AndyButland's task in 5m 29s —— View job PR ReviewTarget: Fixes a bug where editing an image that was wrapped in an
Suggestions
ApprovedGood fix with solid test coverage across both the plain-image and figure code paths. The extraction helpers are clean and well-documented, and the round-trip regression tests give good confidence in the mark-preservation logic. Well done! |
There was a problem hiding this comment.
Pull request overview
This PR fixes a Tiptap RTE regression where editing an image would drop its wrapping link by ensuring the original image node’s inline marks (notably the umbLink mark) are preserved when the image/figure is rebuilt. It also cleans up the Figure extension so newly created figures don’t emit an empty figcaption="" attribute.
Changes:
- Preserve image marks during image replacement by extracting marks from the current selection (including when the selection lands on an atomic
figure) and passing them throughinsertContent. - Preserve existing
figurenode attributes during figure rebuilds. - Simplify the Figure extension HTML parsing and default
figcaptiontonull, with added unit tests covering these scenarios.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Umbraco.Web.UI.Client/src/packages/tiptap/extensions/media-picker/media-picker.tiptap-toolbar.utils.ts | Adds helper utilities to extract image marks, enclosing figure attrs, and figure image/caption data for safe rebuilds. |
| src/Umbraco.Web.UI.Client/src/packages/tiptap/extensions/media-picker/media-picker.tiptap-toolbar.utils.test.ts | Adds unit tests validating mark/attrs extraction and round-trip preservation via insertContent. |
| src/Umbraco.Web.UI.Client/src/packages/tiptap/extensions/media-picker/media-picker.tiptap-toolbar-api.ts | Updates media-picker toolbar behavior to forward extracted marks and preserve figure attributes when inserting/replacing content. |
| src/Umbraco.Web.UI.Client/src/packages/tiptap/extensions/figure/figure.tiptap-extension.ts | Stops mirroring <figcaption> text into a figure attribute and defaults figcaption to null to avoid empty attribute emission. |
Description
As reported in #23013, editing an image in the Tiptap RTE was discarding any
<a>that wrapped the image.Currently the rebuild inserts a fresh image node with no marks so the
umbLinkmark representing the wrapping link was dropped.The fix captures and forwards the inline marks on the original image onto the replacement.
In testing I found an odd behaviour with an empty
figcaptionattribute being created. This was also fixed whilst preserving any existing wrapping<figure>'s attributes, by removing the Figure extension'sparseHTMLmirror that copied the inner<figcaption>text into the figure'sfigcaptionattribute and defaulting the attribute tonullso freshly-built figures no longer emitfigcaption="".Fixes #23013.
Testing
Automated
For automated testing I've extracted helpers (
extractImageMarks,extractFigureAttrs,extractFigureImageData) to a sibling utils module, and covered with 14 unit tests.Manual
Two starting markup shapes cover the two code paths. In each case, after editing the image, the wrapping
<a>(with all its attributes) should still surround the<img>in the resulting markup.Swap the
data-udiandlocalLinkGUID for real values from your local environment; thesrcURL doesn't matter (the editor regenerates it on submit).Image wrapped directly in a link
<img>is still wrapped in<a data-router-slot="disabled" href="/{localLink:...}" title="My Page" type="document">— all four<a>attributes intact.Image inside a figure with a caption
<img>is still wrapped in the original<a>with all attributes, and the<figcaption>text is unchanged.<figure>element does not gain an emptyfigcaption=""attribute.