fix(editor): improve affine-link toolbar (#11159)

Closes: [BS-2884](https://linear.app/affine-design/issue/BS-2884/[ui]-hover-邮箱的-toolbar)
This commit is contained in:
fundon
2025-03-25 07:58:41 +00:00
parent 4d15c32242
commit 583bbf3463
3 changed files with 59 additions and 3 deletions
@@ -316,6 +316,17 @@ export const builtinInlineLinkToolbarConfig = {
)
return false;
const { link } = target;
try {
const url = new URL(link);
if (!url.protocol.startsWith('http')) {
return false;
}
} catch (err) {
console.error(err);
return false;
}
const { model } = target.block;
const parent = model.parent;
if (!parent) return false;
+4 -3
View File
@@ -148,10 +148,11 @@ export function isUrlInClipboard(clipboardData: DataTransfer) {
return isValidUrl(url);
}
export function getHostName(url: string) {
export function getHostName(link: string) {
try {
return new URL(url).hostname;
const url = new URL(link);
return url.hostname || url.pathname;
} catch {
return url;
return link;
}
}