-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make insertNodes append children to the first element
This restores the behavior that changed in #5002 particularly when pasting into links and other inline elements. Fixes #5251.
- Loading branch information
Showing
2 changed files
with
128 additions
and
16 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
packages/lexical-playground/__tests__/regression/5251-paste-into-inline-element.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
|
||
import { | ||
moveToLineBeginning, | ||
moveToNextWord, | ||
moveToPrevWord, | ||
selectCharacters, | ||
} from '../keyboardShortcuts/index.mjs'; | ||
import { | ||
assertHTML, | ||
click, | ||
copyToClipboard, | ||
focusEditor, | ||
html, | ||
initialize, | ||
pasteFromClipboard, | ||
pressToggleBold, | ||
test, | ||
} from '../utils/index.mjs'; | ||
|
||
test.describe('Regression test #5251', () => { | ||
test.beforeEach(({isCollab, page}) => initialize({isCollab, page})); | ||
test('Correctly pastes rich content inside an inline element', async ({ | ||
isPlainText, | ||
page, | ||
}) => { | ||
test.skip(isPlainText); | ||
await focusEditor(page); | ||
|
||
// Root | ||
// |- Paragraph | ||
// |- Text "Hello " | ||
// |- Text "bold" { format: bold } | ||
// |- Text " " | ||
// |- Link | ||
// |- Text "World" | ||
await page.keyboard.type('Hello '); | ||
await pressToggleBold(page); | ||
await page.keyboard.type('bold'); | ||
await pressToggleBold(page); | ||
await page.keyboard.type(' World'); | ||
await moveToPrevWord(page); | ||
await selectCharacters(page, 'right', 'World'.length); | ||
await click(page, '.link'); | ||
|
||
// Copy "Hello bold" | ||
await moveToLineBeginning(page); | ||
await selectCharacters(page, 'right', 'Hello bold'.length); | ||
const clipboard = await copyToClipboard(page); | ||
|
||
// Drop "bold" | ||
await page.keyboard.press('ArrowLeft'); | ||
await moveToNextWord(page); | ||
await selectCharacters(page, 'right', 'bold '.length); | ||
await page.keyboard.press('Delete'); | ||
|
||
// Check our current state | ||
await assertHTML( | ||
page, | ||
html` | ||
<p | ||
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr" | ||
dir="ltr"> | ||
<span data-lexical-text="true">Hello</span> | ||
<a | ||
href="https://" | ||
rel="noreferrer" | ||
class="PlaygroundEditorTheme__link PlaygroundEditorTheme__ltr" | ||
dir="ltr"> | ||
<span data-lexical-text="true">World</span> | ||
</a> | ||
</p> | ||
`, | ||
); | ||
|
||
// Replace "Wor" with the contents of the clipboard | ||
await page.keyboard.press('ArrowRight'); | ||
await selectCharacters(page, 'right', 'Wor'.length); | ||
await pasteFromClipboard(page, clipboard); | ||
|
||
await assertHTML( | ||
page, | ||
html` | ||
<p | ||
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr" | ||
dir="ltr"> | ||
<span data-lexical-text="true">Hello</span> | ||
<a | ||
href="https://" | ||
rel="noreferrer" | ||
class="PlaygroundEditorTheme__link PlaygroundEditorTheme__ltr" | ||
dir="ltr"> | ||
<span data-lexical-text="true">Hello</span> | ||
<strong | ||
class="PlaygroundEditorTheme__textBold" | ||
data-lexical-text="true"> | ||
bold | ||
</strong> | ||
<span data-lexical-text="true">ld</span> | ||
</a> | ||
</p> | ||
`, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters