From e06d5e1c8dd774928d7d6caeb8180d588934d290 Mon Sep 17 00:00:00 2001 From: danielchim Date: Mon, 10 Jul 2023 02:37:49 +0800 Subject: [PATCH] fix: page mode shortcut (#3097) --- .../editor-mode-switch/index.tsx | 22 +++++++++++++++---- .../editor-mode-switch/style.ts | 11 ++++++++++ apps/web/src/hooks/affine/use-shortcuts.ts | 4 ++-- packages/component/src/ui/tooltip/tooltip.tsx | 7 +++++- packages/i18n/src/resources/en.json | 3 ++- 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/index.tsx b/apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/index.tsx index 3843f9045a..70ef4b1fa0 100644 --- a/apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/index.tsx +++ b/apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/index.tsx @@ -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 ( +
+ Switch + + {!environment.isServer && environment.isMacOs ? '⌥ + S' : 'Alt + S'} + +
+ ); +}; 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 ( - + }> { + return { + marginLeft: '5px', + fontSize: '4px', + paddingLeft: '5px', + paddingRight: '5px', + backgroundColor: '#55545A', + borderRadius: '4px', + }; +}); diff --git a/apps/web/src/hooks/affine/use-shortcuts.ts b/apps/web/src/hooks/affine/use-shortcuts.ts index ffc59e1759..5c37700323 100644 --- a/apps/web/src/hooks/affine/use-shortcuts.ts +++ b/apps/web/src/hooks/affine/use-shortcuts.ts @@ -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']()]: '⌘ + ⌥ + ↓', diff --git a/packages/component/src/ui/tooltip/tooltip.tsx b/packages/component/src/ui/tooltip/tooltip.tsx index 96038d884c..d8e5175f5f 100644 --- a/packages/component/src/ui/tooltip/tooltip.tsx +++ b/packages/component/src/ui/tooltip/tooltip.tsx @@ -1,5 +1,5 @@ -import type { TooltipProps } from '@mui/material'; import { NoSsr } from '@mui/material'; +import type { ReactElement } from 'react'; import { styled } from '../../styles'; import { Popper, type PopperProps } from '../popper'; @@ -18,6 +18,11 @@ const StyledTooltip = styled(StyledPopperContainer)(() => { }; }); +interface TooltipProps { + content: string | ReactElement; + placement?: PopperProps['placement']; + children: ReactElement; +} export const Tooltip = (props: PopperProps & Omit) => { const { content, placement = 'top-start', children } = props; return ( diff --git a/packages/i18n/src/resources/en.json b/packages/i18n/src/resources/en.json index 091a3f977d..fef108c6a4 100644 --- a/packages/i18n/src/resources/en.json +++ b/packages/i18n/src/resources/en.json @@ -405,5 +405,6 @@ "Workspace Settings with name": "{{name}}'s Settings", "You can customize your workspace here.": "You can customise your workspace here.", "Font Style": "Font Style", - "Choose your font style": "Choose your font style" + "Choose your font style": "Choose your font style", + "Switch": "Switch" }