lexical icon indicating copy to clipboard operation
lexical copied to clipboard

Bug: Editor becomes uneditable when a block DecoratorNode is the only root child

Open mayrang opened this issue 6 months ago • 0 comments

Lexical version: 0.44.0 (latest main, commit e65fcd7c8)

Steps To Reproduce

  1. Open https://playground.lexical.dev/
  2. Insert a block DecoratorBlockNode (e.g. YouTube via the slash menu, URL like https://www.youtube.com/watch?v=dQw4w9WgXcQ)
  3. Remove the paragraph above the decorator (Backspace at the paragraph start) so the block decorator becomes the only root child
  4. Click the decorator so it is focused as a NodeSelection (a focus ring appears)
  5. Press Enter

Link to code example: https://playground.lexical.dev/

The current behavior

Nothing happens. The KEY_ENTER_COMMAND handler registered by registerRichText bails out at the $isRangeSelection(selection) guard — for a NodeSelection it just returns false. There is no paragraph to type into, and the keyboard has no way out of the NodeSelection state.

https://github.com/user-attachments/assets/d697fc05-3cdb-4c3d-899d-b00f26cbaa56

The expected behavior

A new empty paragraph should be inserted after the decorator and the caret should land in it, so the user can keep typing — matching the common pattern in other editors where pressing Enter on a selected block creates a new line below it.

Impact of fix

Whenever a user removes the surrounding paragraphs of a block decorator (image, YouTube, etc.), the editor becomes uneditable from the keyboard. The fix is small (a NodeSelection branch in the rich-text Enter handler) and unblocks an otherwise common state.

mayrang avatar May 18 '26 06:05 mayrang