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 (
{formatCombo(b.combo)}