Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix list paste issue #3239

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/lexical-list/src/LexicalListNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
*
*/

import type {Spread} from 'lexical';

import {
addClassNamesToElement,
removeClassNamesFromElement,
} from '@lexical/utils';
import {
$createTextNode,
$isElementNode,
DOMConversionMap,
DOMConversionOutput,
EditorConfig,
Expand All @@ -23,6 +22,7 @@ import {
LexicalNode,
NodeKey,
SerializedElementNode,
Spread,
} from 'lexical';

import {$createListItemNode, $isListItemNode, ListItemNode} from '.';
Expand Down Expand Up @@ -163,9 +163,11 @@ export class ListNode extends ElementNode {

if ($isListNode(currentNode)) {
listItemNode.append(currentNode);
} else {
} else if ($isElementNode(currentNode)) {
const textNode = $createTextNode(currentNode.getTextContent());
listItemNode.append(textNode);
} else {
listItemNode.append(currentNode);
}
super.append(listItemNode);
}
Expand Down
188 changes: 188 additions & 0 deletions packages/lexical-playground/__tests__/e2e/CopyAndPaste.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
moveToLineEnd,
moveToPrevWord,
selectAll,
selectCharacters,
} from '../keyboardShortcuts/index.mjs';
import {
assertHTML,
Expand Down Expand Up @@ -1011,6 +1012,193 @@ test.describe('CopyAndPaste', () => {
});
});

test('Copy list items and paste into list', async ({
page,
isPlainText,
isCollab,
}) => {
test.skip(isPlainText);

await focusEditor(page);

await page.keyboard.type('- one');
await page.keyboard.press('Enter');
await page.keyboard.type('two');
await page.keyboard.press('Enter');
await page.keyboard.type('three');
await page.keyboard.press('Enter');
await page.keyboard.type('four');
await page.keyboard.press('Enter');
await page.keyboard.type('five');

await selectAll(page);

await assertHTML(
page,
html`
<ul class="PlaygroundEditorTheme__ul">
<li
value="1"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">one</span>
</li>
<li
value="2"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">two</span>
</li>
<li
value="3"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">three</span>
</li>
<li
value="4"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">four</span>
</li>
<li
value="5"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">five</span>
</li>
</ul>
`,
);

const clipboard = await copyToClipboard(page);

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

await page.keyboard.type('12345');

await assertHTML(
page,
html`
<ul class="PlaygroundEditorTheme__ul">
<li
value="1"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">one</span>
</li>
<li
value="2"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">two</span>
</li>
<li
value="3"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">three</span>
</li>
<li
value="4"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">four</span>
</li>
<li
value="5"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">five</span>
</li>
</ul>
<p class="PlaygroundEditorTheme__paragraph">
<span data-lexical-text="true">12345</span>
</p>
`,
);

await page.keyboard.press('ArrowLeft');
await page.keyboard.press('ArrowLeft');
await selectCharacters(page, 'left', 1);

await pasteFromClipboard(page, clipboard);

await assertHTML(
page,
html`
<ul class="PlaygroundEditorTheme__ul">
<li
value="1"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">one</span>
</li>
<li
value="2"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">two</span>
</li>
<li
value="3"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">three</span>
</li>
<li
value="4"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">four</span>
</li>
<li
value="5"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">five</span>
</li>
</ul>
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">12one</span>
</p>
<ul class="PlaygroundEditorTheme__ul">
<li
value="1"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">two</span>
</li>
<li
value="2"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">three</span>
</li>
<li
value="3"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">four</span>
</li>
<li
value="4"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">five</span>
</li>
<li value="5" class="PlaygroundEditorTheme__listItem">
<span data-lexical-text="true">45</span>
</li>
</ul>
`,
);
});

test('Copy and paste of list items and paste back into list on an existing item', async ({
page,
isPlainText,
Expand Down