From 6b266e3a1b559863e6955a5d2b1ca78e03b2afb3 Mon Sep 17 00:00:00 2001 From: fundon Date: Mon, 9 Sep 2024 03:11:20 +0000 Subject: [PATCH] fix(core): link copying and pasting (#8157) Related to: https://github.com/toeverything/blocksuite/pull/8233 --- .../specs/custom/database-block.ts | 18 ++++++++++++------ .../specs/custom/widgets/toolbar.ts | 16 ++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/database-block.ts b/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/database-block.ts index 932fed1b8a..7470fde07e 100644 --- a/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/database-block.ts +++ b/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/database-block.ts @@ -72,14 +72,20 @@ function createCopyLinkToBlockMenuItem( const str = generateUrl(options); if (!str) return; - track.doc.editor.toolbar.copyBlockToLink({ type: model.flavour }); + const type = model.flavour; + const title = editor.doc.title$.value; + const page = editor.editorContainer$.value; - navigator.clipboard - .writeText(str) + page?.host?.std.clipboard + .writeToClipboard(items => { + items['text/plain'] = str; + // wrap a link + items['text/html'] = `${title}`; + return items; + }) .then(() => { - notify.success({ - title: I18n['Copied link to clipboard'](), - }); + track.doc.editor.toolbar.copyBlockToLink({ type }); + notify.success({ title: I18n['Copied link to clipboard']() }); }) .catch(console.error); }, diff --git a/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/widgets/toolbar.ts b/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/widgets/toolbar.ts index 0c508d5c28..3a3a8aa3c2 100644 --- a/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/widgets/toolbar.ts +++ b/packages/frontend/core/src/components/blocksuite/block-suite-editor/specs/custom/widgets/toolbar.ts @@ -114,14 +114,18 @@ function createCopyLinkToBlockMenuItem( return; } - track.doc.editor.toolbar.copyBlockToLink({ type }); + const title = editor.doc.title$.value; - navigator.clipboard - .writeText(str) + ctx.std.clipboard + .writeToClipboard(items => { + items['text/plain'] = str; + // wrap a link + items['text/html'] = `${title}`; + return items; + }) .then(() => { - notify.success({ - title: I18n['Copied link to clipboard'](), - }); + track.doc.editor.toolbar.copyBlockToLink({ type }); + notify.success({ title: I18n['Copied link to clipboard']() }); }) .catch(console.error);