diff --git a/packages/lexical-playground/__tests__/e2e/Links.spec.mjs b/packages/lexical-playground/__tests__/e2e/Links.spec.mjs index 91d78d160b6..3eb5d1d4373 100644 --- a/packages/lexical-playground/__tests__/e2e/Links.spec.mjs +++ b/packages/lexical-playground/__tests__/e2e/Links.spec.mjs @@ -375,6 +375,57 @@ test.describe('Links', () => { ); }); + test(`Can create a link in a list and insert a paragraph at the start`, async ({ + page, + }) => { + await focusEditor(page); + await page.keyboard.type('- hello'); + await selectCharacters(page, 'left', 5); + + // link + await click(page, '.link'); + + await moveLeft(page, 1); + + await assertHTML( + page, + html` + + `, + ); + + await page.keyboard.press('Enter'); + + await assertHTML( + page, + html` + + `, + ); + }); + test(`Can create a link with some text after, insert paragraph, then backspace, it should merge correctly`, async ({ page, }) => { diff --git a/packages/lexical/src/LexicalSelection.js b/packages/lexical/src/LexicalSelection.js index a270c411808..d601f3f77d3 100644 --- a/packages/lexical/src/LexicalSelection.js +++ b/packages/lexical/src/LexicalSelection.js @@ -1421,7 +1421,14 @@ export class RangeSelection implements BaseSelection { nodesToMoveLength > 0 && currentElement.isInline() ) { - currentElement.getParentOrThrow().insertBefore($createParagraphNode()); + const parent = currentElement.getParentOrThrow(); + const newElement = parent.insertNewAfter(this); + if ($isElementNode(newElement)) { + const children = parent.getChildren(); + for (let i = 0; i < children.length; i++) { + newElement.append(children[i]); + } + } return; } const newElement = currentElement.insertNewAfter(this);