Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jamzi opened this issue May 20, 2025 · 2 comments · May be fixed by #7552
Open

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

jamzi opened this issue May 20, 2025 · 2 comments · May be fixed by #7552

Comments

@jamzi
Copy link

jamzi commented May 20, 2025

CleanShot.2025-05-20.at.16.11.16.mp4

The issue occurs with the one character links inside the paragraph, standalone one character link works great, also if you select the single character it works.

I'm assuming it has something to do with node selection, as you can see in the tree view, it selects the previous and next node for this edge case instead of selecting the child text inside the link node.

https://github.com/facebook/lexical/blob/main/packages/lexical-playground/src/plugins/FloatingLinkEditorPlugin/index.tsx#L342

Lexical version: 0.31.2

Steps To Reproduce

  1. Use the Lexical Playground
  2. Create or modify the editor content to include the one character link inside the paragraph.
  3. Try to click on the link, it should open the popover.

The expected behavior

I should be able to somehow select the one character link and open the associated toolbar.

Impact of fix

Let me know if there are any suggested workarounds for this.

@etrepum
Copy link
Collaborator

etrepum commented May 20, 2025

In this case the RangeSelection normalizes to the closest TextNode which is always going to be one of the siblings of the LinkNode. If it were to behave like three adjacent TextNodes then the selection should land inside the link when it is at the end.

You could probably work around this with a SELECTION_CHANGE_COMMAND listener that detects this specific scenario (collapsed RangeSelection at offset 0 of a TextNode with a previous sibling that is an inline ElementNode containing a 1 character TextNode) but it's probably something better handled at a lower level.

The ultimate problem here is that boundaries of TextNode and ElementNode always have multiple selection coordinates that are all visually equivalent and have "zero distance" between them, so heuristics have to be used to determine which one makes the most sense in any given situation.

@etrepum
Copy link
Collaborator

etrepum commented May 20, 2025

Internally the relevant code would be resolveSelectionPointOnBoundary in LexicalSelection.ts

kirandash pushed a commit to bgwebagency/lexical that referenced this issue May 21, 2025
The selection system previously normalized to the closest TextNode sibling
when dealing with link nodes, making one-character links difficult to
select. This change modifies resolveSelectionPointOnBoundary to:

- Keep selection inside link nodes instead of normalizing to siblings
- Handle one-character links specially by maintaining internal selection
- Preserve existing behavior for other inline elements

Fixes facebook#7551
kirandash pushed a commit to bgwebagency/lexical that referenced this issue May 21, 2025
…node

This change modifies resolveSelectionPointOnBoundary to:

- Handle all inline elements consistently based on structure rather than type
- Keep selection inside single-text-node inline elements
- Remove type-specific checks in favor of structural checks
- Maintain existing behavior for multi-child inline elements

Fixes facebook#7551

Co-authored-by: Bob Ippolito <bob@redivi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants