fix link bubble showing wrong URL on selection
Created by: jedmund
Summary
- The link bubble wasn't showing when selecting linked text, and when it did show, it sometimes displayed the wrong URL
- Root cause:
editor.isActive('link')requires the link mark to cover the entire selection to return true — so even selecting one extra character around a link would cause it to fail silently - Switched both bubble menus to walk the actual document marks to detect links, which catches any overlap
- Made the displayed href reactive (
$derived.by) so it always pulls from the current editor state instead of being set once and going stale
What changed
ComposerLinkBubble — now handles both cursor-on-link and selection-containing-link (previously cursor-only). Uses $derived.by() for the href so it's always current.
ComposerBubbleMenu — yields to the link bubble when the selection contains any link marks. The link button now only adds new links to unlinked text.
Test plan
-
Click within linked text (cursor, no selection) → link bubble shows correct URL -
Select linked text → link bubble shows correct URL -
Reload page with saved links → select a link → still shows correct URL -
Add a new link, then select an older link → shows the older link's URL, not the new one -
Select non-linked text → formatting bubble shows as usual -
Click link button on non-linked text → link input appears