Skip to content

[lexical-playground] Bug Fix: Show floating link editor for single-character links#8392

Merged
etrepum merged 1 commit intofacebook:mainfrom
mayrang:fix/single-char-link-selection
Apr 26, 2026
Merged

[lexical-playground] Bug Fix: Show floating link editor for single-character links#8392
etrepum merged 1 commit intofacebook:mainfrom
mayrang:fix/single-char-link-selection

Conversation

@mayrang
Copy link
Copy Markdown
Contributor

@mayrang mayrang commented Apr 26, 2026

Description

Fixes #8184

When a link contains only one character, the floating link editor popup never appeared when navigating with arrow keys. The cursor always lands on a node boundary where the browser reports it as outside the link.

Added a $getAdjacentLinkNode helper that applies right bias for collapsed selections, as suggested by @etrepum in #8184: when the cursor is at the end of a TextNode and the next sibling is a LinkNode, treat it as being on the link. Applied in $updateToolbar, $updateLinkEditor (URL), and $updateLinkEditor (position).

Test Plan

  1. Type "hello A world", select "A", insert a link
  2. Move cursor with arrow keys across the link
  3. Before: popup never appears for the single-character link
  4. After: popup appears when cursor enters the link boundary from the left

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Apr 26, 2026 3:48pm
lexical-playground Ready Ready Preview, Comment Apr 26, 2026 3:48pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 26, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Apr 26, 2026
Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

Would it clean things up in here if there was a getSelectedLinkNode helper function that did all of the checks (selection of link directly, parent is a link, right-biased sibling of text is a link) and returned the best candidate?

…aracter links

Apply right bias for collapsed selections at text node boundaries so
the floating link editor appears when the cursor is adjacent to a
LinkNode. Previously, single-character links never showed the popup
because the cursor always landed on the boundary where the browser
reports it as outside the link.

Fixes facebook#8184
@mayrang
Copy link
Copy Markdown
Contributor Author

mayrang commented Apr 26, 2026

That's much cleaner. refactored into a single $getSelectedLinkNode helper that handles all three cases. Force-pushed. Thanks!

@etrepum etrepum added this pull request to the merge queue Apr 26, 2026
Merged via the queue into facebook:main with commit 7ae43d1 Apr 26, 2026
41 checks passed
@etrepum etrepum mentioned this pull request Apr 27, 2026
Copy link
Copy Markdown
Contributor Author

@mayrang mayrang left a comment

Choose a reason for hiding this comment

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

(duplicate comment, please ignore)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Selection does not include LinkNode when it contains only one character

2 participants