Skip to content
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

Bug: RangeSelection using root splices text from last node #4658

Closed
9larsons opened this issue Jun 14, 2023 · 0 comments · Fixed by #4659 or #4664
Closed

Bug: RangeSelection using root splices text from last node #4658

9larsons opened this issue Jun 14, 2023 · 0 comments · Fixed by #4659 or #4664
Labels
all-platforms-bug core Reconciler, DOM, Selection, Node, Events, Composition core-team core team priority issue

Comments

@9larsons
Copy link
Contributor

Lexical version: v0.11.1

Steps To Reproduce

  1. Create root selection on an editor with text as the last node
  2. Delete the selection

Link to code example:
https://github.com/facebook/lexical/pull/4586/files this PR is what surfaced this issue, but I'm also trying to implement a similar solution (using root-based RangeSelection) as a workaround for another bug and am running in to the issue there as well.

editor.registerCommand(
    KEY_MODIFIER_COMMAND,
    (event) => {
        const {metaKey} = event;
        if (metaKey && event.keyCode === 65) {
          const root = $getRoot();
          root.select(0, root.getChildrenSize());
          event.preventDefault();
          return true;
        }
}

This works great with a decorator node in the content, but if it's just text (or text is the last child of root), the content is spliced because of this line.

The current behavior

If a text node is the last node in root, the content is spliced based on the root offset, which doesn't make sense.

The expected behavior

If a text node is the last node in root, do not splice the content.

Note, the workaround to this is inserting a blank paragraph node on select all, but that can also be confusing/annoying for users.

9larsons added a commit to 9larsons/lexical that referenced this issue Jun 14, 2023
closes facebook#4658
-root key range selections should not splice text
@zurfyx zurfyx added all-platforms-bug core Reconciler, DOM, Selection, Node, Events, Composition core-team core team priority issue labels Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
all-platforms-bug core Reconciler, DOM, Selection, Node, Events, Composition core-team core team priority issue
Projects
None yet
2 participants