diff --git a/src/components/editor/WelcomeView.tsx b/src/components/editor/WelcomeView.tsx index 4a1b34f..667ea58 100644 --- a/src/components/editor/WelcomeView.tsx +++ b/src/components/editor/WelcomeView.tsx @@ -1,3 +1,4 @@ +import { useState } from 'react' import { FileText, Folder, Slash, MousePointer, Save, Search, Moon, Plus, Hash, Star, Image, Code2, @@ -73,19 +74,24 @@ const FEATURES = [ }, ] -const SHORTCUTS = [ - { desc: '粗体', mac: ['⌘', 'B'], win: ['Ctrl', 'B'] }, - { desc: '斜体', mac: ['⌘', 'I'], win: ['Ctrl', 'I'] }, - { desc: '下划线', mac: ['⌘', 'U'], win: ['Ctrl', 'U'] }, - { desc: '行内代码', mac: ['⌘', 'E'], win: ['Ctrl', 'E'] }, - { desc: '撤销', mac: ['⌘', 'Z'], win: ['Ctrl', 'Z'] }, - { desc: '重做', mac: ['⌘', '⇧', 'Z'], win: ['Ctrl', 'Y'] }, - { desc: '命令菜单', mac: ['/'], win: ['/'] }, - { desc: '退出专注模式', mac: ['Esc'], win: ['Esc'] }, +const SHORTCUTS: { mac: string[]; win: string[]; desc: string }[] = [ + { mac: ['⌘', 'B'], win: ['Ctrl', 'B'], desc: '粗体' }, + { mac: ['⌘', 'I'], win: ['Ctrl', 'I'], desc: '斜体' }, + { mac: ['⌘', 'U'], win: ['Ctrl', 'U'], desc: '下划线' }, + { mac: ['⌘', 'E'], win: ['Ctrl', 'E'], desc: '行内代码' }, + { mac: ['⌘', 'Z'], win: ['Ctrl', 'Z'], desc: '撤销' }, + { mac: ['⌘', '⇧', 'Z'], win: ['Ctrl', 'Y'], desc: '重做' }, + { mac: ['/'], win: ['/'], desc: '命令菜单' }, + { mac: ['Esc'], win: ['Esc'], desc: '退出专注模式' }, ] +function detectOS(): 'mac' | 'win' { + return /mac/i.test(navigator.platform) ? 'mac' : 'win' +} + export function WelcomeView() { const { createNote } = useAppStore() + const [os, setOs] = useState<'mac' | 'win'>(detectOS) return (
{/* Shortcuts */} -

- 常用快捷键 -

-
- {/* Header */} -
+

- 操作 - macOS - Windows + 常用快捷键 +

+
+ {(['mac', 'win'] as const).map(opt => ( + + ))}
+
+
{SHORTCUTS.map((s, i) => (
0 ? '1px solid var(--border)' : 'none', background: 'var(--bg-subtle)', }} > {s.desc} -
- {s.mac.map(k => ( - - {k} - - ))} -
-
- {s.win.map(k => ( +
+ {s[os].map(k => (