Skip to content

Bug: new paragraph can be inserted inside inline node #8083

@levensta

Description

@levensta

Lexical version: v0.39.0

Steps To Reproduce

  1. Copy the title from a google search result and pasting it into the editor.
  2. Press Enter at the end of the line
Screen.Recording.2026-01-17.at.23.58.57.mov

Link to code example:

https://playground.lexical.dev/#doc=H4sIAAAAAAAAE51SwW6DMAz9F58jStWKtvmAnXaYxHHawSIeRHMTZEwFqvj3KbCua08Tp-TZeu_5ObkCOa9RSkUlsFeQGDWdVePZCQWw7_8GjhQ9g80NfEY5o87Xc3QEFkKqMBjodORUAANKg4KFVxp8Nfd0bFNrrhu4kHQ-BrDb6cOA80KVzjj0zHePpOSDo7D4_Wg0hM6H-kHGgGKdejtYocg-fD3JCfGNqyg16S_ymkIuoBdOpqptZzcbXtJmji6bNWO0KFgLts1zNBr05b72BMvbqlfYzB_h4Q0mA4ydlnghB3Z7KI7FcZ_vitP-YKCLvVSJ98Y41hL74P6yIc92pyyH6Rs6Z8oscQIAAA

The current behavior

New paragraph inserted inside LinkNode

 root
  └ (47) paragraph 
    └ (48) link "https://lexical.dev/"
      ├ (49) heading 
      | └ (50) text "Lexical"
>     ├ (52) paragraph 

The expected behavior

New paragraph inserted outside LinkNode

 root
  ├ (47) paragraph 
  | └ (48) link "https://lexical.dev/"
  |   ├ (49) heading 
  |   | └ (50) text "Lexical"
> └ (52) paragraph 

Impact of fix

I discovered this corner case while reading the bug description in this PR. In cases where a link or any other inline node contains a block element, all new nodes created by pressing Enter will be placed inside that inline element.

This may be normal behavior in the case of a header split or other elements, but the insertion of a new paragraph should be outside the inline element and the parent block

Ideally, I can imagine that normalizing the tree when inserting new nodes could be done in such a way that each inline ElementNode containing block elements is copied for each block and wraps the highest inline ElementNode or TextNode. But maybe it is only necessary to correct the case with the insertion of a new paragraph

Metadata

Metadata

Assignees

No one assigned

    Labels

    copy+pasteRelates to Lexical Copy/Paste

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions