import { useEffect } from 'react'; import { useKeymap, formatCombo } from './keymap-service'; // 按 Typora 官方菜单分组的快捷键速查 const GROUPS: { label: string; ids: string[] }[] = [ { label: '📁 文件', ids: ['newDoc', 'newWindow', 'openFile', 'quickOpen', 'save', 'saveAs', 'toggleSettings', 'closeTab', 'reopenTab'] }, { label: '✏️ 基础编辑', ids: ['find', 'replace', 'copyMd', 'pastePlain', 'selectLine', 'selectWord', 'selectSameFormat', 'deleteWord', 'docStart', 'docEnd'] }, { label: '📝 Markdown 格式', ids: ['bold', 'italic', 'underline', 'strike', 'inlineCode', 'link', 'insertImage', 'clearFormat'] }, { label: '📑 段落、标题、块', ids: ['heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6', 'paragraph', 'headingUp', 'headingDown', 'blockquote', 'bulletList', 'orderedList', 'codeBlock', 'mathBlock', 'table', 'indent', 'outdent', 'moveUp', 'moveDown'] }, { label: '👁️ 视图', ids: ['toggleSidebar', 'toggleOutline', 'toggleInfo', 'fileTree', 'focusMode', 'typewriter', 'fullscreen', 'focusSearch', 'toggleCheat'] }, ]; export function CheatSheet({ onClose }: { onClose: () => void }) { const bindings = useKeymap(s => s.bindings); // FR-B6:Esc 关闭速查面板 useEffect(() => { const onEsc = (e: KeyboardEvent) => { if (e.key === 'Escape') { e.preventDefault(); onClose(); } }; window.addEventListener('keydown', onEsc, true); return () => window.removeEventListener('keydown', onEsc, true); }, [onClose]); const byId = new Map(bindings.map(b => [b.id, b] as const)); return (
{ if (e.target === e.currentTarget) onClose(); }} style={{ position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.5)', display: 'flex', alignItems: 'center', justifyContent: 'center', zIndex: 1500 }}>
快捷键速查(Typora 标准)
{GROUPS.map(g => { const items = g.ids.map(id => byId.get(id)).filter((b): b is NonNullable => !!b); if (items.length === 0) return null; return (
{g.label}
{items.map(b => (
{b.label} {formatCombo(b.combo)}
))}
); })}
? 打开此面板 · Esc 关闭弹层
); }