feat(core): copy event for image (#8219)

fix AF-1383
This commit is contained in:
pengx17 2024-09-13 10:28:28 +00:00
parent b1e61245ee
commit 2ac4a846f7
No known key found for this signature in database
GPG Key ID: 23F23D9E8B3971ED
2 changed files with 39 additions and 1 deletions

View File

@ -265,11 +265,20 @@ const ImagePreviewModalImpl = ({
event.stopPropagation();
};
const onCopyEvent = (event: ClipboardEvent) => {
event.preventDefault();
event.stopPropagation();
copyHandler();
};
document.addEventListener('keyup', handleKeyUp);
document.addEventListener('copy', onCopyEvent);
return () => {
document.removeEventListener('keyup', handleKeyUp);
document.removeEventListener('copy', onCopyEvent);
};
}, [blockModel, blocksuiteDoc, onBlockIdChange]);
}, [blockModel, blocksuiteDoc, copyHandler, onBlockIdChange]);
useErrorBoundary(error);

View File

@ -375,6 +375,35 @@ test('image able to copy to clipboard', async ({ page }) => {
).toBeVisible();
});
test('image preview should be able to copy image to clipboard on copy event', async ({
page,
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await clickNewPageButton(page);
let blobId: string;
{
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/large-image.png');
await page.locator('affine-page-image').first().dblclick();
await page.waitForTimeout(500);
blobId = (await page
.getByTestId('image-preview-modal')
.locator('img')
.first()
.getAttribute('data-blob-id')) as string;
expect(blobId).toBeTruthy();
}
const locator = page.getByTestId('image-preview-modal');
await expect(locator).toBeVisible();
await page.dispatchEvent('body', 'copy');
await expect(
page.locator('[data-testid=affine-toast]:has-text("Copied to clipboard.")')
).toBeVisible();
});
test('image able to download', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);