mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-02 18:09:58 +08:00
feat(core): add history shortcut (#4595)
This commit is contained in:
@@ -27,7 +27,9 @@ import { forwardRef, useCallback, useEffect, useMemo } from 'react';
|
||||
import { openWorkspaceListModalAtom } from '../../atoms';
|
||||
import { useHistoryAtom } from '../../atoms/history';
|
||||
import { useAppSetting } from '../../atoms/settings';
|
||||
import { useGeneralShortcuts } from '../../hooks/affine/use-shortcuts';
|
||||
import { useTrashModalHelper } from '../../hooks/affine/use-trash-modal-helper';
|
||||
import { useRegisterBlocksuiteEditorCommands } from '../../hooks/use-shortcut-commands';
|
||||
import type { AllWorkspace } from '../../shared';
|
||||
import { currentCollectionsAtom } from '../../utils/user-setting';
|
||||
import { CollectionsList } from '../pure/workspace-slider-bar/collections';
|
||||
@@ -105,6 +107,8 @@ export const RootAppSidebar = ({
|
||||
const [openUserWorkspaceList, setOpenUserWorkspaceList] = useAtom(
|
||||
openWorkspaceListModalAtom
|
||||
);
|
||||
const generalShortcutsInfo = useGeneralShortcuts();
|
||||
|
||||
const onClickNewPage = useCallback(async () => {
|
||||
const page = createPage();
|
||||
await page.waitForLoaded();
|
||||
@@ -161,7 +165,7 @@ export const RootAppSidebar = ({
|
||||
const closeUserWorkspaceList = useCallback(() => {
|
||||
setOpenUserWorkspaceList(false);
|
||||
}, [setOpenUserWorkspaceList]);
|
||||
|
||||
useRegisterBlocksuiteEditorCommands(router.back, router.forward);
|
||||
return (
|
||||
<>
|
||||
<AppSidebar
|
||||
@@ -173,6 +177,7 @@ export const RootAppSidebar = ({
|
||||
environment.isMacOs
|
||||
)
|
||||
}
|
||||
generalShortcutsInfo={generalShortcutsInfo}
|
||||
>
|
||||
<MoveToTrash.ConfirmModal
|
||||
open={trashConfirmOpen}
|
||||
|
||||
@@ -81,9 +81,8 @@ export const useWinGeneralKeyboardShortcuts = (): ShortcutMap => {
|
||||
// not implement yet
|
||||
// [t('appendDailyNote')]: 'Ctrl + Alt + A',
|
||||
[t('expandOrCollapseSidebar')]: ['Ctrl', '/'],
|
||||
// not implement yet
|
||||
// [t('goBack')]: 'Ctrl + [',
|
||||
// [t('goForward')]: 'Ctrl + ]',
|
||||
[t('goBack')]: ['Ctrl + ['],
|
||||
[t('goForward')]: ['Ctrl + ]'],
|
||||
}),
|
||||
[t]
|
||||
);
|
||||
@@ -98,9 +97,8 @@ export const useMacGeneralKeyboardShortcuts = (): ShortcutMap => {
|
||||
// not implement yet
|
||||
// [t('appendDailyNote')]: '⌘ + ⌥ + A',
|
||||
[t('expandOrCollapseSidebar')]: ['⌘', '/'],
|
||||
// not implement yet
|
||||
// [t('goBack')]: '⌘ + [',
|
||||
// [t('goForward')]: '⌘ + ]',
|
||||
[t('goBack')]: ['⌘ + ['],
|
||||
[t('goForward')]: ['⌘ + ]'],
|
||||
}),
|
||||
[t]
|
||||
);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import {
|
||||
PreconditionStrategy,
|
||||
registerAffineCommand,
|
||||
} from '@toeverything/infra/command';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export function useRegisterBlocksuiteEditorCommands(
|
||||
back: () => unknown,
|
||||
forward: () => unknown
|
||||
) {
|
||||
useEffect(() => {
|
||||
const unsubs: Array<() => void> = [];
|
||||
|
||||
unsubs.push(
|
||||
registerAffineCommand({
|
||||
id: 'affine:shortcut-history-go-back',
|
||||
category: 'affine:general',
|
||||
preconditionStrategy: PreconditionStrategy.Never,
|
||||
icon: 'none',
|
||||
label: 'go back',
|
||||
keyBinding: {
|
||||
binding: '$mod+[',
|
||||
},
|
||||
run() {
|
||||
back();
|
||||
},
|
||||
})
|
||||
);
|
||||
unsubs.push(
|
||||
registerAffineCommand({
|
||||
id: 'affine:shortcut-history-go-forward',
|
||||
category: 'affine:general',
|
||||
preconditionStrategy: PreconditionStrategy.Never,
|
||||
icon: 'none',
|
||||
label: 'go forward',
|
||||
keyBinding: {
|
||||
binding: '$mod+]',
|
||||
},
|
||||
run() {
|
||||
forward();
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
return () => {
|
||||
unsubs.forEach(unsub => unsub());
|
||||
};
|
||||
}, [back, forward]);
|
||||
}
|
||||
Reference in New Issue
Block a user