fix: page mode shortcut (#3097)

(cherry picked from commit e06d5e1c8d)
This commit is contained in:
danielchim
2023-07-10 02:37:49 +08:00
committed by Alex Yang
parent 994a5d9b54
commit 9bc42c7eca
5 changed files with 39 additions and 8 deletions

View File

@@ -9,7 +9,7 @@ import { useEffect } from 'react';
import { pageSettingFamily } from '../../../../atoms';
import type { BlockSuiteWorkspace } from '../../../../shared';
import { toast } from '../../../../utils';
import { StyledEditorModeSwitch } from './style';
import { StyledEditorModeSwitch, StyledKeyboardItem } from './style';
import { EdgelessSwitchItem, PageSwitchItem } from './switch-items';
export type EditorModeSwitchProps = {
@@ -18,7 +18,16 @@ export type EditorModeSwitchProps = {
pageId: string;
style?: CSSProperties;
};
const TooltipContent = () => {
return (
<div>
Switch
<StyledKeyboardItem>
{!environment.isServer && environment.isMacOs ? '⌥ + S' : 'Alt + S'}
</StyledKeyboardItem>
</div>
);
};
export const EditorModeSwitch = ({
style,
blockSuiteWorkspace,
@@ -34,7 +43,11 @@ export const EditorModeSwitch = ({
const { trash } = pageMeta;
useEffect(() => {
const keydown = (e: KeyboardEvent) => {
if ((e.key === 's' && e.metaKey) || (e.key === 's' && e.altKey)) {
if (
!environment.isServer && environment.isMacOs
? e.key === 'ß'
: e.key === 's' && e.altKey
) {
e.preventDefault();
setSetting(setting => {
if (setting?.mode !== 'page') {
@@ -51,8 +64,9 @@ export const EditorModeSwitch = ({
return () =>
document.removeEventListener('keydown', keydown, { capture: true });
}, [setSetting, t]);
return (
<Tooltip content={'Switch ⌘ + S'}>
<Tooltip content={<TooltipContent />}>
<StyledEditorModeSwitch
style={style}
switchLeft={currentMode === 'page'}

View File

@@ -53,3 +53,14 @@ export const StyledSwitchItem = styled('button')<{
},
};
});
export const StyledKeyboardItem = styled('span')(() => {
return {
marginLeft: '5px',
fontSize: '4px',
paddingLeft: '5px',
paddingRight: '5px',
backgroundColor: '#55545A',
borderRadius: '4px',
};
});

View File

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