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(blocks): should paste text content as note on edgeless when copy from doc mode #8827

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
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 @@
pressEnter,
pressEnterWithShortkey,
pressEscape,
selectAllByKeyboard,
setEdgelessTool,
switchEditorMode,
type,
Expand Down Expand Up @@ -59,8 +60,8 @@
);
await expect(newNote).toBeVisible();
const blocks = newNote.locator('[data-block-id]');
await expect(blocks.nth(0)).toContainText('hello');

Check failure on line 63 in tests/edgeless/paste-block.spec.ts

View workflow job for this annotation

GitHub Actions / E2E Test (10)

edgeless/paste-block.spec.ts:40:3 › pasting blocks › pasting a note block

1) edgeless/paste-block.spec.ts:40:3 › pasting blocks › pasting a note block ───────────────────── Error: Timed out 5000ms waiting for expect(locator).toContainText(expected) Locator: locator('affine-edgeless-note[data-block-id="10"]').locator('[data-block-id]').first() - Expected string - 1 + Received string + 21 - hello + + + + + ​ + + + Type '/' for commands + + + + + + + + + + + + + Call log: - expect.toContainText with timeout 5000ms - waiting for locator('affine-edgeless-note[data-block-id="10"]').locator('[data-block-id]').first() - locator resolved to <affine-paragraph data-block-id="11">…</affine-paragraph> - unexpected value " ​ Type '/' for commands " - locator resolved to <affine-paragraph data-block-id="11">…</affine-paragraph> - unexpected value " ​ Type '/' for commands " - locator resolved to <affine-paragraph data-block-id="11">…</affine-paragraph> - unexpected value " ​ Type '/' for commands " - locator resolved to <affine-paragraph data-block-id="11">…</affine-paragraph> - unexpected value " ​ Type '/' for commands " - locator resolved to <affine-paragraph data-block-id="11">…</affine-paragraph> - unexpected value " ​ Type '/' for commands " - locator resolved to <affine-paragraph data-block-id="11">…</affine-paragraph> - unexpected value " ​ Type '/' for commands " - locator resolved to <affine-paragraph data-block-id="11">…</affine-paragraph> - unexpected value " ​ Type '/' for commands " - locator resolved to <affine-paragraph data-block-id="11">…</affine-paragraph> - unexpected value " ​ Type '/' for commands " - locator resolved to <affine-paragraph data-block-id=
await expect(blocks.nth(1).locator('.resizable-img')).toBeVisible();

Check failure on line 64 in tests/edgeless/paste-block.spec.ts

View workflow job for this annotation

GitHub Actions / E2E Test (10)

edgeless/paste-block.spec.ts:40:3 › pasting blocks › pasting a note block

1) edgeless/paste-block.spec.ts:40:3 › pasting blocks › pasting a note block ───────────────────── Error: Timed out 5000ms waiting for expect(locator).toBeVisible() Locator: locator('affine-edgeless-note[data-block-id="10"]').locator('[data-block-id]').nth(1).locator('.resizable-img') Expected: visible Received: <element(s) not found> Call log: - expect.toBeVisible with timeout 5000ms - waiting for locator('affine-edgeless-note[data-block-id="10"]').locator('[data-block-id]').nth(1).locator('.resizable-img') 62 | const blocks = newNote.locator('[data-block-id]'); 63 | await expect(blocks.nth(0)).toContainText('hello'); > 64 | await expect(blocks.nth(1).locator('.resizable-img')).toBeVisible(); | ^ 65 | await expect(blocks.nth(2)).toContainText('world'); 66 | await expect(blocks.nth(3)).toContainText('code'); 67 | }); at /home/runner/work/blocksuite/blocksuite/tests/edgeless/paste-block.spec.ts:64:59
await expect(blocks.nth(2)).toContainText('world');
await expect(blocks.nth(3)).toContainText('code');
});
Expand Down Expand Up @@ -94,4 +95,33 @@
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');
});
});
Loading