Skip to content

feat: configurable keyboard shortcuts for the panel toggles (mod+b / mod+t) - #97

Open
dailin3 wants to merge 1 commit into
omdsh-dev:mainfrom
dailin3:feat/keyboard-shortcuts
Open

feat: configurable keyboard shortcuts for the panel toggles (mod+b / mod+t)#97
dailin3 wants to merge 1 commit into
omdsh-dev:mainfrom
dailin3:feat/keyboard-shortcuts

Conversation

@dailin3

@dailin3 dailin3 commented Aug 15, 2026

Copy link
Copy Markdown

背景

用户在 GUI 里需要快捷唤起/收起侧边栏和底部终端面板。本 PR 新增两条可配置快捷键,默认:

  • mod+b(macOS 为 ⌘B,Windows/Linux 为 Ctrl+B)→ 唤起/收起右侧侧边栏
  • mod+t(⌘T / Ctrl+T)→ 唤起/收起底部面板(终端);窄窗口下切换合并抽屉

改动

  • prefsSidebarPrefs 新增 shortcutPanel / shortcutTerminal(规范组合键字符串:mod|meta|ctrl[+alt][+shift]+key,空字符串 = 禁用);PrefsSchema 注册两个字段;parsePrefs 把非法值规范化为 ''(禁用),绝不武装一个会在打字时误触发的组合。
  • 纯词汇模块 src/client/shortcut-combo.ts(零依赖、无 react):解析/规范化/精确修饰键匹配/平台化显示标签(⌘B / Ctrl+B)。精确修饰键语义:mod+b 不会吞掉 ctrl+alt+b 这类别的组合。
  • 监听器 src/client/shortcuts.ts:document 捕获阶段 keydown,实时读 prefs(设置提交即换绑),跳过 IME 组合/repeat/快捷键录制控件内按键,随 fiber 释放。
  • 设置 UI:侧边卡片「常规」区新增两行按键录制控件(KeyCaptureInput)——点击后按下新组合键即可改绑,Backspace/Delete 禁用;两个面板开关按钮的 tooltip 显示当前绑定的快捷键。
  • 文案:zh/en 词典 + README 快捷键表。
  • 测试tests/shortcuts.spec.ts(词汇+prefs 集成)、tests/key-capture-input.spec.tsx(SSR 渲染),并同步 unit/plugin-shape/smoke/side-card 里 prefs 形状断言。

已知限制

  • 浏览器页面内 Cmd/Ctrl+T 属于浏览器保留键(新标签页),普通浏览器标签页里页面 JS 收不到;在桌面壳(Tauri/Pake 包装)里可用。Cmd/Ctrl+B 无此限制。
  • 快捷键全部可改绑,冲突组合与平台相关(如 Chrome 里 Cmd+T),用户可在设置里换。

测试

pnpm run typecheck ✅;pnpm run test:新增/相关用例全绿(本机沙箱环境下 node-pty 的 posix_spawnp 用例失败为环境问题,与本次改动无关)。

…mod+t)

- SidebarPrefs gains shortcutPanel (mod+b) and shortcutTerminal (mod+t),
  canonical combo strings (mod|meta|ctrl[+alt][+shift]+key) or '' (disabled).
- New pure combo vocabulary module (src/client/shortcut-combo.ts): parse /
  normalize / match with exact-modifier semantics / platform labels, kept
  import-free so the client prefs parser shares the grammar without react.
- New document-level capture listener (src/client/shortcuts.ts): Cmd/Ctrl+B
  toggles the right sidebar, Cmd/Ctrl+T the bottom terminal panel (the
  merged drawer on narrow viewports); reads prefs live, skips IME/repeat/
  capture-control events, disposed with the fiber.
- Side card settings gain two key-capture rows (KeyCaptureInput): click,
  press the new chord; Backspace/Delete disables. Toggle tooltips show the
  bound shortcut.
- PrefsSchema registers the two fields; parsePrefs normalizes malformed
  values to '' (disabled) instead of arming a typing-hijack combo.
- Tests: shortcuts.spec.ts (vocabulary + prefs integration),
  key-capture-input.spec.tsx (SSR), updated prefs-shape expectations in
  unit/plugin-shape/smoke/side-card specs. README shortcut tables updated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant