feat(editor): add more open doc options to editor toolbar (#9588)

fix AF-2036, AF-2092
This commit is contained in:
pengx17
2025-01-09 08:04:21 +00:00
parent 890a962196
commit f78857bb11
41 changed files with 558 additions and 271 deletions
@@ -1,7 +1,7 @@
import { IconButton } from '@affine/component';
import { usePageHelper } from '@affine/core/components/blocksuite/block-suite-page-list/utils';
import { WorkspaceService } from '@affine/core/modules/workspace';
import { isNewTabTrigger } from '@affine/core/utils';
import { inferOpenMode } from '@affine/core/utils';
import { useI18n } from '@affine/i18n';
import track from '@affine/track';
import { PlusIcon } from '@blocksuite/icons/rc';
@@ -25,7 +25,7 @@ export function AddPageButton({ className, style }: AddPageButtonProps) {
const onClickNewPage = useCallback(
(e?: MouseEvent) => {
pageHelper.createPage(undefined, isNewTabTrigger(e) ? 'new-tab' : true);
pageHelper.createPage(undefined, { at: inferOpenMode(e) });
track.$.navigationPanel.$.createDoc();
},
[pageHelper]
@@ -15,7 +15,7 @@ import {
} from '@affine/core/modules/favorite';
import { WorkspaceService } from '@affine/core/modules/workspace';
import type { AffineDNDData } from '@affine/core/types/dnd';
import { isNewTabTrigger } from '@affine/core/utils';
import { inferOpenMode } from '@affine/core/utils';
import { useI18n } from '@affine/i18n';
import { track } from '@affine/track';
import { PlusIcon } from '@blocksuite/icons/rc';
@@ -81,10 +81,7 @@ export const ExplorerFavorites = () => {
const handleCreateNewFavoriteDoc: MouseEventHandler = useCallback(
e => {
const newDoc = createPage(
undefined,
isNewTabTrigger(e) ? 'new-tab' : true
);
const newDoc = createPage(undefined, { at: inferOpenMode(e) });
favoriteService.favoriteList.add(
'doc',
newDoc.id,
@@ -27,13 +27,13 @@ export class DesktopWorkbenchNewTabHandler
constructor(private readonly electronApi: DesktopApiService) {
super();
}
handle({ basename, to }: { basename: string; to: To }) {
handle({ basename, to, show }: { basename: string; to: To; show: boolean }) {
const path = typeof to === 'string' ? parsePath(to) : to;
this.electronApi.api.handler.ui
.addTab({
basename,
view: { path },
show: false,
show: show,
})
.catch(console.error);
}
@@ -240,6 +240,7 @@ export const SplitViewPanel = memo(function SplitViewPanel({
dropTargetRef.current = node;
dragRef.current = node;
}}
data-is-active={isActive && views.length > 1 && !draggingEntity}
className={styles.splitViewPanelDrag}
>
<div draggable={false} className={styles.splitViewPanelContent}>
@@ -74,7 +74,7 @@ export const splitViewPanelDrag = style({
transition: 'box-shadow 0.5s cubic-bezier(0.16, 1, 0.3, 1)',
},
'[data-is-active="true"] &::after': {
'[data-is-active="true"]&::after': {
boxShadow: `inset 0 0 0 1px ${cssVarV2('button/primary')}`,
},
@@ -1,7 +1,7 @@
import { useDraggable } from '@affine/component';
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
import type { AffineDNDData, AffineDNDEntity } from '@affine/core/types/dnd';
import { isNewTabTrigger } from '@affine/core/utils';
import { inferOpenMode as inferOpenAt } from '@affine/core/utils';
import { useLiveData, useServices } from '@toeverything/infra';
import { type To } from 'history';
import { forwardRef, type MouseEvent } from 'react';
@@ -62,13 +62,8 @@ export const WorkbenchLink = forwardRef<HTMLAnchorElement, WorkbenchLinkProps>(
if (event.defaultPrevented) {
return;
}
const at = (() => {
if (isNewTabTrigger(event)) {
return BUILD_CONFIG.isElectron && event.altKey ? 'tail' : 'new-tab';
}
return 'active';
})();
workbench.open(to, { at, replaceHistory });
const at = inferOpenAt(event);
workbench.open(to, { at, replaceHistory, show: false });
event.preventDefault();
event.stopPropagation();
},