diff --git a/apps/core/src/components/root-app-sidebar/index.tsx b/apps/core/src/components/root-app-sidebar/index.tsx index c6c496211..7c97d09e7 100644 --- a/apps/core/src/components/root-app-sidebar/index.tsx +++ b/apps/core/src/components/root-app-sidebar/index.tsx @@ -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 ( <> { // 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] ); diff --git a/apps/core/src/hooks/use-shortcut-commands.ts b/apps/core/src/hooks/use-shortcut-commands.ts new file mode 100644 index 000000000..e8003ddac --- /dev/null +++ b/apps/core/src/hooks/use-shortcut-commands.ts @@ -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]); +} diff --git a/packages/component/src/components/app-sidebar/index.tsx b/packages/component/src/components/app-sidebar/index.tsx index 49e3b597e..78afc6023 100644 --- a/packages/component/src/components/app-sidebar/index.tsx +++ b/packages/component/src/components/app-sidebar/index.tsx @@ -110,7 +110,10 @@ export function AppSidebar(props: AppSidebarProps): ReactElement { data-enable-animation={enableAnimation && !isResizing} >