fix(hotkeys): 快捷键系统性修复——1.Ctrl+N onNewDoc 原为空函数, 实现新建文档全流程(dialog+fileCreate+openDoc); 2.Ctrl+backslash clearFormat 原无处理器(actions 缺失), 加 onClearFormat 调用 editor.chain().clearNodes().unsetAllMarks(); 3.use-hotkeys 重写: 移除 hotkeys-js 依赖, 全部绑定统一用捕获阶段 keydown 拦截(先于 Electron 菜单), 加 e.code 符号键映射修复 Shift+符号键匹配; 4.编辑器作用域键在输入框聚焦时仍放行 find(Ctrl+F); keymap-all E2E 8 项覆盖全部 12 默认快捷键

This commit is contained in:
hunter-dev
2026-08-26 19:05:01 +08:00
parent a6458c03e9
commit 8c47d27979
3 changed files with 234 additions and 40 deletions
+24 -1
View File
@@ -1,5 +1,9 @@
import { useState, useEffect } from 'react';
import { useStore } from './store';
import { invoke } from './ipc-client';
import { IPC } from '@hunter/shared';
import { useDialog } from './features/dialog/dialog-store';
import { useEditorShared } from './features/editor/editor-shared-store';
import { FileTree } from './features/file-tree/FileTree';
import { Editor } from './features/editor/Editor';
import { Toolbar } from './features/toolbar/Toolbar';
@@ -47,7 +51,26 @@ export function App() {
window.addEventListener('beforeunload', onBeforeUnload);
return () => window.removeEventListener('beforeunload', onBeforeUnload);
}, []);
useGlobalHotkeys({ onNewDoc: () => {}, onSave: () => useStore.getState().saveNow(), onFocusSearch: () => { const el = document.querySelector('input[placeholder*="搜索"]') as HTMLInputElement; el?.focus(); }, onToggleOutline: () => layout.toggleOutline(), onCheat: () => setShowCheat(true), onSettings: () => setShowSettings(true), onFind: () => { window.dispatchEvent(new CustomEvent('dsh-toggle-find')); } });
useGlobalHotkeys({
onNewDoc: async () => {
const { showInput } = useDialog.getState();
const name = await showInput('新建文档', '输入文档标题…');
if (!name) return;
const { path } = await invoke(IPC.fileCreate, { basePath: '', name, isFolder: false });
await useStore.getState().loadTree();
await useStore.getState().openDoc(path);
},
onSave: () => useStore.getState().saveNow(),
onFocusSearch: () => { const el = document.querySelector('input[placeholder*="搜索"]') as HTMLInputElement; el?.focus(); },
onToggleOutline: () => layout.toggleOutline(),
onCheat: () => setShowCheat(true),
onSettings: () => setShowSettings(true),
onFind: () => { window.dispatchEvent(new CustomEvent('dsh-toggle-find')); },
onClearFormat: () => {
const ed = useEditorShared.getState().editor;
ed?.chain().focus().clearNodes().unsetAllMarks().run();
},
});
// 编辑器样式随设置生效(FR-编辑器设置真实生效)
useEffect(() => { document.documentElement.style.setProperty('--editor-font-size', settings.fontSize + 'px'); document.documentElement.style.setProperty('--editor-font-family', settings.fontFamily); document.documentElement.style.setProperty('--editor-white-space', settings.wordWrap ? 'pre-wrap' : 'pre'); }, [settings.fontSize, settings.fontFamily, settings.wordWrap]);