Skip to content

[lexical] Bug Fix: Keep selection inside single-child inline elements#8772

Open
mayrang wants to merge 2 commits into
facebook:mainfrom
mayrang:fix/7551-one-char-link-selection
Open

[lexical] Bug Fix: Keep selection inside single-child inline elements#8772
mayrang wants to merge 2 commits into
facebook:mainfrom
mayrang:fix/7551-one-char-link-selection

Conversation

@mayrang

@mayrang mayrang commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Description

resolveSelectionPointOnBoundary normalizes selection points at inline element boundaries. For inline elements that return canInsertTextAfter() === false (like LinkNode), it pushes the cursor outside at the right edge. When the inline element contains only a single child, offset 0 is the left edge and offset 1 is the right edge — both get normalized outward, making it impossible to place the cursor inside.

This adds a parent.getChildrenSize() !== 1 guard to the right-edge normalization branch, so single-child inline elements keep the cursor inside at the right edge. Left-edge normalization (which keeps left bias) is unchanged.

Closes #7551

Test plan

  • pnpm vitest run --project unit packages/lexical/src/__tests__/unit/LexicalSelection.test.ts — 69 tests pass
    • Single-child link: cursor stays at offset 1 inside the link
    • Multi-child link: cursor normalizes to the next sibling (existing behavior preserved)
  • Manual playground:
    • Type "hello", select "hello", insert link, click at end of link text: cursor stays inside the link and further typing extends the link
    • Multi-word link: cursor at end of last child still normalizes outward
  • tsc / eslint / prettier clean

@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Jul 2, 2026 12:54pm
lexical-playground Ready Ready Preview Jul 2, 2026 12:54pm

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 Jul 2, 2026
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Can't click on 1 character text links inside the paragraph

2 participants