Skip to content

fix(Link): show link popup for single-character selections#1028

Open
temrjan wants to merge 1 commit intogravity-ui:mainfrom
temrjan:fix/link-popup-short-selection
Open

fix(Link): show link popup for single-character selections#1028
temrjan wants to merge 1 commit intogravity-ui:mainfrom
temrjan:fix/link-popup-short-selection

Conversation

@temrjan
Copy link
Copy Markdown

@temrjan temrjan commented Mar 25, 2026

Summary

Fixes #789 — link creation popup does not appear when selected text is less than 2 characters.

Root cause: The link mark spec has inclusive: false. After toggleMark applies the link to a 1-character selection (e.g. "a" at positions 1–2), the cursor is placed at $to.pos - 1 = 1 — the left boundary of the mark. With inclusive: false, $from.marks() at this position does not include the link mark, so isMarkActive() returns false and LinkTooltipPlugin never shows the popup.

For 2+ character selections this works because the cursor lands between two marked characters, where $from.marks() naturally includes the link.

Fix: After setSelection, explicitly set storedMarks from the adjacent text node's marks. This ensures isMarkActive() sees the link mark regardless of cursor position relative to the mark boundary.

Test plan

  • Added linkEnhanceActions.test.ts with 3 tests:
    • should add link mark to a single-character selection — verifies storedMarks contain the link
    • should add link mark to a multi-character selection — regression
    • should not activate on empty selection
  • All 14 Link-related tests pass

🤖 Generated with Claude Code

When adding a link to a 1-character selection, the cursor was placed
at the left edge of the non-inclusive link mark. Because the mark has
`inclusive: false`, `$from.marks()` at the boundary did not include
the link mark, so `isMarkActive()` returned false and the tooltip
was never shown.

Fix: set `storedMarks` from the adjacent text node after positioning
the cursor, ensuring the link mark is active regardless of position.

Closes gravity-ui#789

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gravity-ui
Copy link
Copy Markdown

gravity-ui bot commented Mar 25, 2026

🎭 Playwright Report

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.

Link creation popup does not appear if selected text is less than 2 characters

1 participant