feat: ctrl click to open embeded doc in new tab (#8401)

fix AF-1176
depends on https://github.com/toeverything/blocksuite/pull/8478
This commit is contained in:
pengx17
2024-10-08 02:06:59 +00:00
parent 80b28cc2a8
commit a3dc074574
4 changed files with 83 additions and 1 deletions

View File

@@ -44,6 +44,7 @@ import { BlocksuiteEditorJournalDocTitle } from './journal-doc-title';
import {
patchDocModeService,
patchEdgelessClipboard,
patchEmbedLinkedDocBlockConfig,
patchForSharedPage,
patchNotificationService,
patchParseDocUrlExtension,
@@ -135,6 +136,7 @@ const usePatchSpecs = (shared: boolean, mode: DocMode) => {
patched = patched.concat(patchEdgelessClipboard());
patched = patched.concat(patchParseDocUrlExtension(framework));
patched = patched.concat(patchQuickSearchService(framework));
patched = patched.concat(patchEmbedLinkedDocBlockConfig(framework));
if (shared) {
patched = patched.concat(patchForSharedPage());
}

View File

@@ -20,6 +20,8 @@ import {
RecentDocsQuickSearchSession,
} from '@affine/core/modules/quicksearch';
import { ExternalLinksQuickSearchSession } from '@affine/core/modules/quicksearch/impls/external-links';
import { WorkbenchService } from '@affine/core/modules/workbench';
import { isNewTabTrigger } from '@affine/core/utils';
import { DebugLogger } from '@affine/debug';
import { track } from '@affine/track';
import {
@@ -41,6 +43,7 @@ import {
DocModeExtension,
EdgelessRootBlockComponent,
EmbedLinkedDocBlockComponent,
EmbedLinkedDocBlockConfigExtension,
NotificationExtension,
ParseDocUrlExtension,
PeekViewExtension,
@@ -224,6 +227,20 @@ export function patchNotificationService({
});
}
export function patchEmbedLinkedDocBlockConfig(framework: FrameworkProvider) {
const getWorkbench = () => framework.get(WorkbenchService).workbench;
return EmbedLinkedDocBlockConfigExtension({
handleClick(e, _, refInfo) {
if (isNewTabTrigger(e)) {
const workbench = getWorkbench();
workbench.openDoc(refInfo.pageId, { at: 'new-tab' });
e.preventDefault();
}
},
});
}
export function patchPeekViewService(service: PeekViewService) {
return PeekViewExtension({
peek: (target: ActivePeekView['target'], template?: TemplateResult) => {

View File

@@ -13,6 +13,6 @@ export function stopEvent(event: BaseSyntheticEvent) {
event.preventDefault();
}
export function isNewTabTrigger(event?: React.MouseEvent) {
export function isNewTabTrigger(event?: React.MouseEvent | MouseEvent) {
return event ? event.ctrlKey || event.metaKey || event.button === 1 : false;
}