Skip to content

Commit

Permalink
fix(blocks): should paste text content as note on edgeless when copy …
Browse files Browse the repository at this point in the history
…from doc mode
  • Loading branch information
donteatfriedrice committed Nov 28, 2024
1 parent 5546741 commit e843596
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/blocks/src/root-block/edgeless/clipboard/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
30 changes: 30 additions & 0 deletions tests/edgeless/paste-block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
pressEnter,
pressEnterWithShortkey,
pressEscape,
selectAllByKeyboard,
setEdgelessTool,
switchEditorMode,
type,
Expand Down Expand Up @@ -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');
});
});

0 comments on commit e843596

Please sign in to comment.