feat: page mode shortcut (#2985)

This commit is contained in:
danielchim
2023-07-04 00:23:53 +08:00
committed by GitHub
parent 7b2acec7c3
commit 32692bd54a
2 changed files with 57 additions and 32 deletions

View File

@@ -1,8 +1,10 @@
import { Tooltip } from '@affine/component';
import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { assertExists } from '@blocksuite/store'; import { assertExists } from '@blocksuite/store';
import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta'; import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
import { useAtom } from 'jotai'; import { useAtom } from 'jotai';
import type { CSSProperties } from 'react'; import type { CSSProperties } from 'react';
import { useEffect } from 'react';
import { pageSettingFamily } from '../../../../atoms'; import { pageSettingFamily } from '../../../../atoms';
import type { BlockSuiteWorkspace } from '../../../../shared'; import type { BlockSuiteWorkspace } from '../../../../shared';
@@ -30,8 +32,27 @@ export const EditorModeSwitch = ({
const t = useAFFiNEI18N(); const t = useAFFiNEI18N();
assertExists(pageMeta); assertExists(pageMeta);
const { trash } = pageMeta; const { trash } = pageMeta;
useEffect(() => {
const keydown = (e: KeyboardEvent) => {
if ((e.key === 's' && e.metaKey) || (e.key === 's' && e.altKey)) {
e.preventDefault();
setSetting(setting => {
if (setting?.mode !== 'page') {
toast(t['com.affine.pageMode']());
return { ...setting, mode: 'page' };
} else {
toast(t['com.affine.edgelessMode']());
return { ...setting, mode: 'edgeless' };
}
});
}
};
document.addEventListener('keydown', keydown, { capture: true });
return () =>
document.removeEventListener('keydown', keydown, { capture: true });
}, [setSetting, t]);
return ( return (
<Tooltip content={'Switch ⌘ + S'}>
<StyledEditorModeSwitch <StyledEditorModeSwitch
style={style} style={style}
switchLeft={currentMode === 'page'} switchLeft={currentMode === 'page'}
@@ -57,12 +78,13 @@ export const EditorModeSwitch = ({
onClick={() => { onClick={() => {
setSetting(setting => { setSetting(setting => {
if (setting?.mode !== 'edgeless') { if (setting?.mode !== 'edgeless') {
toast(t['com.affine.pageMode']()); toast(t['com.affine.edgelessMode']());
} }
return { ...setting, mode: 'edgeless' }; return { ...setting, mode: 'edgeless' };
}); });
}} }}
/> />
</StyledEditorModeSwitch> </StyledEditorModeSwitch>
</Tooltip>
); );
}; };

View File

@@ -91,6 +91,7 @@ export const useWinEdgelessKeyboardShortcuts = (): ShortcutTip => {
[t['Pen']()]: 'P', [t['Pen']()]: 'P',
[t['Hand']()]: 'H', [t['Hand']()]: 'H',
[t['Note']()]: 'N', [t['Note']()]: 'N',
['Switch']: 'Alt + S',
// not implement yet // not implement yet
// [t['Group']()]: 'Ctrl + G', // [t['Group']()]: 'Ctrl + G',
// [t['Ungroup']()]: 'Ctrl + Shift + G', // [t['Ungroup']()]: 'Ctrl + Shift + G',
@@ -122,6 +123,7 @@ export const useMacPageKeyboardShortcuts = (): ShortcutTip => {
[t['Increase indent']()]: 'Tab', [t['Increase indent']()]: 'Tab',
[t['Reduce indent']()]: '⇧+Tab', [t['Reduce indent']()]: '⇧+Tab',
[t['Group as Database']()]: '⌘ + G', [t['Group as Database']()]: '⌘ + G',
['Switch']: '⌘ + S',
// not implement yet // not implement yet
// [t['Move Up']()]: '⌘ + ⌥ + ↑', // [t['Move Up']()]: '⌘ + ⌥ + ↑',
// [t['Move Down']()]: '⌘ + ⌥ + ↓', // [t['Move Down']()]: '⌘ + ⌥ + ↓',
@@ -176,6 +178,7 @@ export const useWinPageKeyboardShortcuts = (): ShortcutTip => {
[t['Increase indent']()]: 'Tab', [t['Increase indent']()]: 'Tab',
[t['Reduce indent']()]: 'Shift+Tab', [t['Reduce indent']()]: 'Shift+Tab',
[t['Group as Database']()]: 'Ctrl + G', [t['Group as Database']()]: 'Ctrl + G',
['Switch']: 'Alt + S',
// not implement yet // not implement yet
// [t['Move Up']()]: 'Ctrl + Alt + ↑', // [t['Move Up']()]: 'Ctrl + Alt + ↑',
// [t['Move Down']()]: 'Ctrl + Alt + ↓', // [t['Move Down']()]: 'Ctrl + Alt + ↓',