Skip to content

Let an image attachment carry a link - #1272

Open
lylo wants to merge 1 commit into
basecamp:mainfrom
lylo:link-attachments
Open

lylo wants to merge 1 commit into
basecamp:mainfrom
lylo:link-attachments

Conversation

@lylo

@lylo lylo commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Closes #1271.

Linking a selected image did nothing: dispatchLink bailed on anything but a range selection. Attachments now carry href, read on import, written on export and in JSON, and null when absent so it is omitted. The link command sets it on the selected image attachments and unlink clears it; other attachment types are ignored. Text links are unchanged, that path has only moved into $linkSelectedText.

Selection#linkUrl answers for both an attachment and the nearest LinkNode, so the dropdown prefills and isInLink lights the toolbar button either way. href joins the attachment sanitiser allowlist.

Rendering the anchor is the host's job, as it is for caption: <action-text-attachment href> is what Trix wrote and what ActionText::Attachment::ATTRIBUTES already preserves.

Test

link_attachment.test.js: link, relink, unlink, dropdown prefill, button state, reload, refusing a PDF, and linking an image inside a gallery. linked_attachment_round_trip_test.rb takes an upload through link, save, render and re-edit and checks href survives Loofah both ways.

Full Playwright suite passes in Chromium. The tables Alt+F10 focus tests fail on main for me too.

Not addressed here

  • No affordance on the figure itself; a linked image shows only through the toolbar button once selected.
  • Cmd-click to open a link does not know about attachments.

@lylo
lylo marked this pull request as ready for review September 29, 2026 10:53
Copilot AI balanced review requested due to automatic review settings September 29, 2026 10:53

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@lylo

lylo commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

Would love thoughts on this @jorgemanrubia @zoltanhosszu if you have time for a quick glace 🙏

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approved

The implementation is consistent across selection, commands, serialization, sanitization, UI state, and automated coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Adds image attachment linking while preserving existing text-link behavior and Action Text compatibility.

Changes:

  • Persists attachment href through HTML, JSON, sanitization, and reloads.
  • Supports linking, relinking, unlinking, and toolbar state for selected images.
  • Adds browser and Rails round-trip coverage.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

File Description
src/​nodes/​action_text_attachment_node.js Imports and exports attachment links.
src/​extensions/​attachments_extension.js Allows sanitized attachment href.
src/​editor/​command_dispatcher.js Handles image link and unlink commands.
src/​editor/​selection.js Exposes attachment link state and URL.
src/​elements/​toolbar.js Reflects linked node selections.
src/​elements/​dropdown/​link.js Prefills attachment link URLs.
test/​browser/​tests/​attachments/​link_attachment.test.js Covers attachment-link interactions.
test/​system/​attachments/​linked_attachment_round_trip_test.rb Verifies Action Text persistence.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

This branch has not been deployed

No deployments
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.

Let an image attachment carry a link

2 participants