From 7c1f8f87263c760894c1655808e7f7b8bec62550 Mon Sep 17 00:00:00 2001 From: MikiVL Date: Sat, 2 May 2026 19:35:24 +0800 Subject: [PATCH] feat: add Windows shortcuts and OS toggle to WelcomeView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Define mac/win key variants for all 8 shortcuts (⌘→Ctrl, ⌘⇧Z→Ctrl+Y) - Auto-detect OS on mount via navigator.platform - Add macOS/Windows pill toggle above shortcuts table Co-Authored-By: Claude Sonnet 4.6 --- src/components/editor/WelcomeView.tsx | 98 +++++++++++++-------------- 1 file changed, 47 insertions(+), 51 deletions(-) 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 => (