fix: page mode shortcut (#3097)

This commit is contained in:
danielchim
2023-07-10 02:37:49 +08:00
committed by GitHub
parent 1c8895f23f
commit e06d5e1c8d
5 changed files with 39 additions and 8 deletions

View File

@@ -9,7 +9,7 @@ import { useEffect } from 'react';
import { pageSettingFamily } from '../../../../atoms'; import { pageSettingFamily } from '../../../../atoms';
import type { BlockSuiteWorkspace } from '../../../../shared'; import type { BlockSuiteWorkspace } from '../../../../shared';
import { toast } from '../../../../utils'; import { toast } from '../../../../utils';
import { StyledEditorModeSwitch } from './style'; import { StyledEditorModeSwitch, StyledKeyboardItem } from './style';
import { EdgelessSwitchItem, PageSwitchItem } from './switch-items'; import { EdgelessSwitchItem, PageSwitchItem } from './switch-items';
export type EditorModeSwitchProps = { export type EditorModeSwitchProps = {
@@ -18,7 +18,16 @@ export type EditorModeSwitchProps = {
pageId: string; pageId: string;
style?: CSSProperties; style?: CSSProperties;
}; };
const TooltipContent = () => {
return (
<div>
Switch
<StyledKeyboardItem>
{!environment.isServer && environment.isMacOs ? '⌥ + S' : 'Alt + S'}
</StyledKeyboardItem>
</div>
);
};
export const EditorModeSwitch = ({ export const EditorModeSwitch = ({
style, style,
blockSuiteWorkspace, blockSuiteWorkspace,
@@ -34,7 +43,11 @@ export const EditorModeSwitch = ({
const { trash } = pageMeta; const { trash } = pageMeta;
useEffect(() => { useEffect(() => {
const keydown = (e: KeyboardEvent) => { 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(); e.preventDefault();
setSetting(setting => { setSetting(setting => {
if (setting?.mode !== 'page') { if (setting?.mode !== 'page') {
@@ -51,8 +64,9 @@ export const EditorModeSwitch = ({
return () => return () =>
document.removeEventListener('keydown', keydown, { capture: true }); document.removeEventListener('keydown', keydown, { capture: true });
}, [setSetting, t]); }, [setSetting, t]);
return ( return (
<Tooltip content={'Switch ⌘ + S'}> <Tooltip content={<TooltipContent />}>
<StyledEditorModeSwitch <StyledEditorModeSwitch
style={style} style={style}
switchLeft={currentMode === 'page'} 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['Pen']()]: 'P',
[t['Hand']()]: 'H', [t['Hand']()]: 'H',
[t['Note']()]: 'N', [t['Note']()]: 'N',
['Switch']: 'Alt + S', [t['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',
@@ -123,7 +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', [t['Switch']()]: ' + S',
// not implement yet // not implement yet
// [t['Move Up']()]: '⌘ + ⌥ + ↑', // [t['Move Up']()]: '⌘ + ⌥ + ↑',
// [t['Move Down']()]: '⌘ + ⌥ + ↓', // [t['Move Down']()]: '⌘ + ⌥ + ↓',

View File

@@ -1,5 +1,5 @@
import type { TooltipProps } from '@mui/material';
import { NoSsr } from '@mui/material'; import { NoSsr } from '@mui/material';
import type { ReactElement } from 'react';
import { styled } from '../../styles'; import { styled } from '../../styles';
import { Popper, type PopperProps } from '../popper'; import { Popper, type PopperProps } from '../popper';
@@ -18,6 +18,11 @@ const StyledTooltip = styled(StyledPopperContainer)(() => {
}; };
}); });
interface TooltipProps {
content: string | ReactElement<any, any>;
placement?: PopperProps['placement'];
children: ReactElement<any, any>;
}
export const Tooltip = (props: PopperProps & Omit<TooltipProps, 'title'>) => { export const Tooltip = (props: PopperProps & Omit<TooltipProps, 'title'>) => {
const { content, placement = 'top-start', children } = props; const { content, placement = 'top-start', children } = props;
return ( return (

View File

@@ -405,5 +405,6 @@
"Workspace Settings with name": "{{name}}'s Settings", "Workspace Settings with name": "{{name}}'s Settings",
"You can customize your workspace here.": "You can customise your workspace here.", "You can customize your workspace here.": "You can customise your workspace here.",
"Font Style": "Font Style", "Font Style": "Font Style",
"Choose your font style": "Choose your font style" "Choose your font style": "Choose your font style",
"Switch": "Switch"
} }