Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: fix copying multiple lists only copied the first one

Abdullah Atta81e343214309
diff --git a/packages/editor/src/extensions/clipboard/clipboard.ts b/packages/editor/src/extensions/clipboard/clipboard.ts
index 09ff03862..fa0664609 100644
--- a/packages/editor/src/extensions/clipboard/clipboard.ts
+++ b/packages/editor/src/extensions/clipboard/clipboard.ts
@@ -53,6 +53,7 @@ export function transformCopied(slice: Slice, view: EditorView): any {
// list formatting but copy it as a paragraph.
const maybeList = slice.content.firstChild;
if (
+ slice.content.childCount === 1 &&
maybeList &&
LIST_NODE_TYPES.includes(maybeList.type.name) &&
maybeList.childCount === 1 &&
diff --git a/packages/editor/src/extensions/clipboard/tests/__snapshots__/clipboard-text-serializer.test.ts.snap b/packages/editor/src/extensions/clipboard/tests/__snapshots__/clipboard-text-serializer.test.ts.snap
index d2668ac05..6d7684096 100644
--- a/packages/editor/src/extensions/clipboard/tests/__snapshots__/clipboard-text-serializer.test.ts.snap
+++ b/packages/editor/src/extensions/clipboard/tests/__snapshots__/clipboard-text-serializer.test.ts.snap
@@ -29,6 +29,82 @@ exports[`copying a single nested list item shouldn't copy the list metadata 1`]
"type": "paragraph",
},
],
- "openStart": 5,
+
+exports[`copying multiple lists shouldn't copy only the first list 1`] = `
+{
+ "content": [
+ {
+ "attrs": {
+ "listType": "",
+ "start": 1,
+ },
+ "content": [
+ {
+ "content": [
+ {
+ "content": [
+ {
+ "text": "Hello",
+ "type": "text",
+ },
+ ],
+ "type": "paragraph",
+ },
+ ],
+ "type": "listItem",
+ },
+ ],
+ "type": "orderedList",
+ },
+ {
+ "attrs": {
+ "listType": "",
+ "start": 1,
+ },
+ "content": [
+ {
+ "content": [
+ {
+ "content": [
+ {
+ "text": "Hello 2",
+ "type": "text",
+ },
+ ],
+ "type": "paragraph",
+ },
+ ],
+ "type": "listItem",
+ },
+ ],
+ "type": "orderedList",
+ },
+ {
+ "attrs": {
+ "listType": "",
+ "start": 1,
+ },
+ "content": [
+ {
+ "content": [
+ {
+ "content": [
+ {
+ "text": "Hello 3",
+ "type": "text",
+ },
+ ],
+ "type": "paragraph",
+ },
+ ],
+ "type": "listItem",
+ },
+ ],
+ "type": "orderedList",
+ },
+ ],
+}
+`;
+
}
`;
diff --git a/packages/editor/src/extensions/clipboard/tests/clipboard-text-serializer.test.ts b/packages/editor/src/extensions/clipboard/tests/clipboard-text-serializer.test.ts
index 03629b8d3..50c0e47d8 100644
--- a/packages/editor/src/extensions/clipboard/tests/clipboard-text-serializer.test.ts
+++ b/packages/editor/src/extensions/clipboard/tests/clipboard-text-serializer.test.ts
@@ -77,7 +77,30 @@ test("copying a single list item shouldn't copy the list metadata", (t) => {
t.expect(
transformCopied(
- editor.state.doc.slice(0, editor.state.doc.nodeSize - 2)
+ editor.state.doc.slice(0, editor.state.doc.nodeSize - 2),
+ editor.view
+ ).toJSON()
+ ).toMatchSnapshot();
+});
+
+
+test("copying multiple lists shouldn't copy only the first list", (t) => {
+ const { editor } = createEditor({
+ initialContent: h("div", [
+ h("ol", [h("li", ["Hello"])]),
+ h("ol", [h("li", ["Hello 2"])]),
+ h("ol", [h("li", ["Hello 3"])])
+ ]).innerHTML,
+ extensions: {
+ orderedList: OrderedList,
+ listItem: ListItem
+ }
+ });
+
+ t.expect(
+ transformCopied(
+ editor.state.doc.slice(0, editor.state.doc.nodeSize - 2),
+ editor.view
).toJSON()
).toMatchSnapshot();
});