Skip to content

Commit

Permalink
[lexical][lexical-playground] Bug Fix: Create line break on paste of …
Browse files Browse the repository at this point in the history
…content type text/html (facebook#6376)

Co-authored-by: Janna Wieneke <[email protected]>
  • Loading branch information
2 people authored and 2wheeh committed Jul 17, 2024
1 parent 220d2a0 commit 4b15060
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,16 @@ describe('LexicalEventHelpers', () => {
],
name: 'two lines + two paragraphs separated by an empty paragraph (2)',
},
{
expectedHTML:
'<p class="editor-paragraph" dir="ltr"><span data-lexical-text="true">line 1</span><br><span data-lexical-text="true">line 2</span></p>',
inputs: [
pasteHTML(
'<p class="p1"><span>line 1</span><span><br></span><span>line 2</span></p>',
),
],
name: 'two lines and br in spans',
},
];

suite.forEach((testUnit, i) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/lexical/src/nodes/LexicalLineBreakNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 ||
Expand Down

0 comments on commit 4b15060

Please sign in to comment.