mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 00:26:51 +08:00
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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1125,3 +1125,47 @@ test('should save open doc mode of internal links', async ({ page }) => {
|
||||
'Open in center peek'
|
||||
);
|
||||
});
|
||||
|
||||
test('should show full email address', async ({ page }) => {
|
||||
await page.keyboard.press('Enter');
|
||||
|
||||
await writeTextToClipboard(page, 'dev@affine.pro');
|
||||
await pasteByKeyboard(page);
|
||||
|
||||
const inlineLink = page.locator('affine-link');
|
||||
|
||||
await expect(inlineLink).toHaveText('dev@affine.pro');
|
||||
|
||||
await inlineLink.hover();
|
||||
|
||||
const { toolbar, switchViewBtn } = toolbarButtons(page);
|
||||
|
||||
await expect(toolbar).toBeVisible();
|
||||
await expect(switchViewBtn).toBeHidden();
|
||||
|
||||
await expect(toolbar.locator('affine-link-preview')).toHaveText(
|
||||
'dev@affine.pro'
|
||||
);
|
||||
});
|
||||
|
||||
test('should not show view toggle button when protocol of link is not http(s)', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.keyboard.press('Enter');
|
||||
|
||||
await writeTextToClipboard(page, 'ftp://affine.pro/blocksuite.pdf');
|
||||
await pasteByKeyboard(page);
|
||||
|
||||
const inlineLink = page.locator('affine-link');
|
||||
|
||||
await expect(inlineLink).toHaveText('ftp://affine.pro/blocksuite.pdf');
|
||||
|
||||
await inlineLink.hover();
|
||||
|
||||
const { toolbar, switchViewBtn } = toolbarButtons(page);
|
||||
|
||||
await expect(toolbar).toBeVisible();
|
||||
await expect(switchViewBtn).toBeHidden();
|
||||
|
||||
await expect(toolbar.locator('affine-link-preview')).toHaveText('affine.pro');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user