diff --git a/packages/blocks/src/root-block/edgeless/clipboard/clipboard.ts b/packages/blocks/src/root-block/edgeless/clipboard/clipboard.ts index 63c91bba045c8..2c50111e76f9d 100644 --- a/packages/blocks/src/root-block/edgeless/clipboard/clipboard.ts +++ b/packages/blocks/src/root-block/edgeless/clipboard/clipboard.ts @@ -1085,12 +1085,14 @@ export class EdgelessClipboardController extends PageClipboard { }); } else { for (let index = 0; index < content.length; index++) { - await this.onBlockSnapshotPaste( - content[index], - this.doc, - noteId, - index - ); + const blockSnapshot = content[index]; + if (blockSnapshot.flavour === 'affine:note') { + for (const child of blockSnapshot.children) { + await this.onBlockSnapshotPaste(child, this.doc, noteId); + } + continue; + } + await this.onBlockSnapshotPaste(content[index], this.doc, noteId); } } diff --git a/tests/edgeless/paste-block.spec.ts b/tests/edgeless/paste-block.spec.ts index c8b85e83e9d86..280ba6954032d 100644 --- a/tests/edgeless/paste-block.spec.ts +++ b/tests/edgeless/paste-block.spec.ts @@ -13,6 +13,7 @@ import { pressEnter, pressEnterWithShortkey, pressEscape, + selectAllByKeyboard, setEdgelessTool, switchEditorMode, type, @@ -94,4 +95,33 @@ test.describe('pasting blocks', () => { await expect(blocks.nth(2)).toContainText('world'); await expect(blocks.nth(3)).toContainText('code'); }); + + test('pasting a note block from doc mode', async ({ page }) => { + await enterPlaygroundRoom(page); + await initEmptyEdgelessState(page); + await focusRichText(page); + await type(page, 'hello world'); + + await selectAllByKeyboard(page); + await copyByKeyboard(page); + + await switchEditorMode(page); + await click(page, { + x: 100, + y: 100, + }); + await pasteByKeyboard(page); + + // not equal to noteId + const noteIds = await getAllEdgelessNoteIds(page); + expect(noteIds.length).toBe(2); + + const newNoteId = noteIds[1]; + const newNote = page.locator( + `affine-edgeless-note[data-block-id="${newNoteId}"]` + ); + await expect(newNote).toBeVisible(); + const blocks = newNote.locator('[data-block-id]'); + await expect(blocks.nth(0)).toContainText('hello world'); + }); });