fix(Link): show link popup for single-character selections#1028
Open
temrjan wants to merge 1 commit intogravity-ui:mainfrom
Open
fix(Link): show link popup for single-character selections#1028temrjan wants to merge 1 commit intogravity-ui:mainfrom
temrjan wants to merge 1 commit intogravity-ui:mainfrom
Conversation
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>
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.
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. AftertoggleMarkapplies 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. Withinclusive: false,$from.marks()at this position does not include the link mark, soisMarkActive()returnsfalseandLinkTooltipPluginnever 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 setstoredMarksfrom the adjacent text node's marks. This ensuresisMarkActive()sees the link mark regardless of cursor position relative to the mark boundary.Test plan
linkEnhanceActions.test.tswith 3 tests:should add link mark to a single-character selection— verifiesstoredMarkscontain the linkshould add link mark to a multi-character selection— regressionshould not activate on empty selection🤖 Generated with Claude Code