facebook / lexical

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
https://lexical.dev
MIT License
17.5k stars 1.45k forks source link

Bug: Should not focus on root element #5968

Open aquarius-wing opened 2 weeks ago

aquarius-wing commented 2 weeks ago

Lexical version:

Steps To Reproduce

  1. Open Playground
  2. Remove all text and type ``` and space key
  3. Type some text like 11111
  4. Press Arrow Up Key multiple times

https://github.com/facebook/lexical/assets/16633962/25e84327-c799-4e6a-a178-0455c8520f82

The current behavior

You'll notice that the selection switches back and forth between the text node and the root node

The expected behavior

Just focus the text node only

StyleT commented 2 weeks ago

Hi! Thanks for noticing this. IMO it actually shall stick to root and stay there. Why? How else can you insert something before that code block? :) Also cursor shall be placed before code block

aquarius-wing commented 2 weeks ago

It's turely work when we want to add text before code block, but it doesn't clear to tell user "now we can insert text before code block!" when focus the root element. Because it seems exactly the same.

In my situation, my solution is when user pressing arrow up key, it will insert a paragraph before directly.

https://github.com/facebook/lexical/assets/16633962/f577fb46-cbef-4a32-a017-9307aa96c3ab

Speaking of which, why do I raise this question? It's to ensure that the focus can be correctly disengaged at the beginning of my editor (not the application shown in the video above).

Example

It's like we have a form, which has input , and a lexical editor, I want the user to be able to navigate between them by pressing the up arrow key.

However, the behavior differs when we focus on the code block, quote and offset is set to 0, it will make the code I write become complex, I believe this is an area that could be improved.

So I suggest, the selection can not be switch to the root element.