Skip to content

Commit

Permalink
Fix bug in insertParagraph (facebook#2058)
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm authored May 3, 2022
1 parent e27b569 commit 9a40b3a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
51 changes: 51 additions & 0 deletions packages/lexical-playground/__tests__/e2e/Links.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
<ul class="PlaygroundEditorTheme__ul">
<li
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr"
value="1">
<a
class="PlaygroundEditorTheme__link PlaygroundEditorTheme__ltr"
dir="ltr"
href="https://">
<span data-lexical-text="true">hello</span>
</a>
</li>
</ul>
`,
);

await page.keyboard.press('Enter');

await assertHTML(
page,
html`
<ul class="PlaygroundEditorTheme__ul">
<li class="PlaygroundEditorTheme__listItem" value="1"><br /></li>
<li class="PlaygroundEditorTheme__listItem" value="2">
<a
class="PlaygroundEditorTheme__link PlaygroundEditorTheme__ltr"
dir="ltr"
href="https://">
<span data-lexical-text="true">hello</span>
</a>
</li>
</ul>
`,
);
});

test(`Can create a link with some text after, insert paragraph, then backspace, it should merge correctly`, async ({
page,
}) => {
Expand Down
9 changes: 8 additions & 1 deletion packages/lexical/src/LexicalSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9a40b3a

Please sign in to comment.