fix(core): link copying and pasting (#8157)

Related to: https://github.com/toeverything/blocksuite/pull/8233
This commit is contained in:
fundon 2024-09-09 03:11:20 +00:00
parent d31565eb98
commit 6b266e3a1b
No known key found for this signature in database
GPG Key ID: 398BFA91AC539CF7
2 changed files with 22 additions and 12 deletions

View File

@ -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'] = `<a title="${title}" href="${str}">${title}</a>`;
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);
},

View File

@ -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'] = `<a title="${title}" href="${str}">${title}</a>`;
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);