Skip to content

Bug: Selecting text in a link to/from the end of the link and deleting deletes the text that is not selected #6991

@amanharwara

Description

@amanharwara

Lexical version: 0.21.0

Steps To Reproduce

  1. Have a link node with a single text node, and another text node as the next sibling of the link node.
  2. In the link, select text from the middle to the end or vice-versa. Either the anchor or the focus should have type element, offset 1 and key of the link node. This can be achieved by starting the selection from the middle then selecting the first character of the next text node and then back to the end of the link, or by starting the selection from the end of the link's text node.
  3. Press backspace or delete to delete the characters

It doesn't seem possible to get the selection into this state if the link node has multiple child text nodes or if the link node does not have a text node sibling next to it.

Link to code example: https://playground.lexical.dev (as of 23rd dec)

The current behavior

Pressing backspace or delete causes the text which is not selected to be deleted and the selection to be collapsed at the start of that text node.

lexical-link-text-deletion.mov

The expected behavior

Only the text that was selected should be deleted.

Impact of fix

This affects any user that tries to delete text at the end of a link and isn't careful about overselecting text initially. If the user starts selecting from the end of the link, then this happens even without overselecting from the sibling text node.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions