diff --git a/packages/lexical-utils/src/__tests__/unit/LexicalEventHelpers.test.tsx b/packages/lexical-utils/src/__tests__/unit/LexicalEventHelpers.test.tsx index be8e06d3b2cf..4847d838d5b2 100644 --- a/packages/lexical-utils/src/__tests__/unit/LexicalEventHelpers.test.tsx +++ b/packages/lexical-utils/src/__tests__/unit/LexicalEventHelpers.test.tsx @@ -668,6 +668,16 @@ describe('LexicalEventHelpers', () => { ], name: 'two lines + two paragraphs separated by an empty paragraph (2)', }, + { + expectedHTML: + '

line 1
line 2

', + inputs: [ + pasteHTML( + '

line 1
line 2

', + ), + ], + name: 'two lines and br in spans', + }, ]; suite.forEach((testUnit, i) => { diff --git a/packages/lexical/src/nodes/LexicalLineBreakNode.ts b/packages/lexical/src/nodes/LexicalLineBreakNode.ts index fc338765022c..dbf3f94a7242 100644 --- a/packages/lexical/src/nodes/LexicalLineBreakNode.ts +++ b/packages/lexical/src/nodes/LexicalLineBreakNode.ts @@ -50,7 +50,7 @@ export class LineBreakNode extends LexicalNode { static importDOM(): DOMConversionMap | null { return { br: (node: Node) => { - if (isOnlyChild(node)) { + if (isOnlyChildInParagraph(node)) { return null; } return { @@ -89,9 +89,9 @@ export function $isLineBreakNode( return node instanceof LineBreakNode; } -function isOnlyChild(node: Node): boolean { +function isOnlyChildInParagraph(node: Node): boolean { const parentElement = node.parentElement; - if (parentElement !== null) { + if (parentElement !== null && parentElement.tagName === 'P') { const firstChild = parentElement.firstChild!; if ( firstChild === node ||