Skip to content

Commit aea4a24

Browse files
author
SqlRush
committed
Accept keybinding accelerator aliases
1 parent 0ca6056 commit aea4a24

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

docs/claude-code-go-rewrite-plan.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ test/parity/ # golden tests against TS/official behavior
354354
- 本轮补充:keybinding JSON loader 现在也递归解包 JSON:API/resource-style `resource`/`attributes`/`properties`/`attrs` wrapper,API/preferences envelope 内的 `keybindings`/`keymap` 可直接加载。
355355
- 本轮补充:keybinding JSON loader 现在把 `data`/`payload`/`body`/`result`/`response``resources``included``collection`/`list`/`children`/`values``nodes``items` 下的数组视为 binding list,数组元素也可直接使用 JSON:API/resource-style `resource`/`node`/`attributes`/`properties` wrapper。
356356
- 本轮补充:keybinding JSON loader 现在也接受 GraphQL connection 风格的 `edges` binding list,binding item 可用 `edges[].node``edge.node` wrapper,外层可递归解包 `viewer`/`node`/`*Connection` wrapper。
357-
- 本轮补充:keybinding JSON loader 现在接受 `keymap`/`keymaps``keyboardShortcuts``hotkeys``userKeybindings``customKeybindings` 等集合字段别名,并同时支持直接 object-map 和嵌套 `bindings` wrapper。
357+
- 本轮补充:keybinding JSON loader 现在接受 `keymap`/`keymaps``keyboardShortcuts``hotkeys``userKeybindings``customKeybindings` 等集合字段别名,并同时支持直接 object-map 和嵌套 `bindings` wrapper;单条 binding 的 key 字段也接受 `accelerator``keystroke``hotKey``keyCombo``keyChord` aliases
358358
- 本轮补充:keybinding JSON loader 现在也接受 provider-style `choices`/`outputs`/`candidates`/`generations` response wrapper,可从 `message.content`、content-block array 和 `content.parts[].text` 里恢复 binding array 或 object map。
359359
- 本轮补充:interaction script 的 per-step keybinding mutation 复用同一套 collection alias、object-map 和 resource wrapper 解析,脚本步骤可直接使用 `keymap``keyboardShortcuts``hotkeys``keyboard``preferences``keybindingConfig` 临时改键位。
360360
- 本轮补充:interaction script 的 `keys` 字段支持 printable text chunk 和空格分隔 named-key sequence,例如 `ctrl-x ctrl-k`,减少官方脚本把连续输入拆成数组的改写成本。

docs/first-second-parity-audit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ M7 progress now includes:
401401
- `internal/tui`: REPL message restore can now rebuild prompt text and image pasted contents from user-message content blocks, `imagePasteIds`, and pasted-content metadata.
402402
- `internal/tui`: Ctrl-S prompt stash now preserves and restores prompt text, cursor position, and pasted-content metadata.
403403
- `internal/tui`: prompt submitted events now retain display text and pasted-content metadata, so downstream runtime code can build text/image content-block messages instead of receiving only the expanded prompt string.
404-
- `internal/tui`: keybinding JSON loading now accepts wrapper object maps, `shortcuts`/`shortcutBindings`, object action fields such as `commandName`/`commandId`, string-array key sequences/chords, and `null`/`false` unbind entries.
404+
- `internal/tui`: keybinding JSON loading now accepts wrapper object maps, `shortcuts`/`shortcutBindings`, object action fields such as `commandName`/`commandId`, key fields such as `accelerator`/`keystroke`/`hotKey`/`keyCombo`/`keyChord`, string-array key sequences/chords, and `null`/`false` unbind entries.
405405
- `internal/tui`: keybinding JSON loading now recurses through outer wrappers such as `data`, `payload`, `settings`, `config`, `keyboard`, and `keymap`, so nested official or third-party preference exports can expose `bindings`/`shortcuts` without manual flattening.
406406
- `internal/tui`: keybinding JSON loading now also recurses through JSON:API/resource-style `resource`, `attributes`, `properties`, and `attrs` wrappers so API/preference envelopes can expose `keybindings` or `keymap` without manual flattening.
407407
- `internal/tui`: keybinding JSON loading now accepts API/GraphQL collection arrays under `data`, `payload`, `body`, `result`, `response`, `resources`, `included`, `collection`, `list`, `children`, `values`, `nodes`, and `items`, with resource-style binding items unwrapped before parsing.

internal/tui/keybinding_loader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func (spec *BindingSpec) UnmarshalJSON(data []byte) error {
278278
}
279279
*spec = BindingSpec{}
280280

281-
key, ok, err := bindingKeyField(fields, "Key", "key", "keys", "key_sequence", "keySequence", "shortcut", "shortcut_key", "shortcutKey", "sequence")
281+
key, ok, err := bindingKeyField(fields, "Key", "key", "keys", "key_sequence", "keySequence", "shortcut", "shortcut_key", "shortcutKey", "shortcut_keys", "shortcutKeys", "sequence", "accelerator", "accelerators", "keystroke", "keyStroke", "hotkey", "hotKey", "key_combo", "keyCombo", "chord", "keyChord")
282282
if err != nil {
283283
return err
284284
}
@@ -332,7 +332,7 @@ func unwrapBindingSpecJSON(data []byte) []byte {
332332

333333
func bindingSpecJSONHasDirectFields(fields map[string]json.RawMessage) bool {
334334
for _, name := range []string{
335-
"Key", "key", "keys", "key_sequence", "keySequence", "shortcut", "shortcut_key", "shortcutKey", "sequence",
335+
"Key", "key", "keys", "key_sequence", "keySequence", "shortcut", "shortcut_key", "shortcutKey", "shortcut_keys", "shortcutKeys", "sequence", "accelerator", "accelerators", "keystroke", "keyStroke", "hotkey", "hotKey", "key_combo", "keyCombo", "chord", "keyChord",
336336
"Action", "action", "command", "action_name", "actionName", "command_name", "commandName", "command_id", "commandId",
337337
} {
338338
if raw, ok := fields[name]; ok && len(bytes.TrimSpace(raw)) > 0 && !bytes.Equal(bytes.TrimSpace(raw), []byte("null")) {

internal/tui/tui_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,10 @@ func TestParseKeyBindingSpecsAcceptsJSONShapes(t *testing.T) {
16351635
"shortcuts": {
16361636
"ctrl-[": false,
16371637
"shift-enter": {"command_id": "insert-newline"},
1638-
"ctrl-w": {"shortcutKey": "ctrl-w", "actionName": "deleteWordBackward"}
1638+
"ctrl-w": {"shortcutKey": "ctrl-w", "actionName": "deleteWordBackward"},
1639+
"ctrl-q": {"accelerator": "ctrl-q", "actionName": "pageUp"},
1640+
"ctrl-v": {"keystroke": "ctrl-v", "actionName": "pageDown"},
1641+
"ctrl-z": {"hotKey": "ctrl-z", "actionName": "redraw"}
16391642
}
16401643
}`))
16411644
if err != nil {
@@ -1654,6 +1657,15 @@ func TestParseKeyBindingSpecsAcceptsJSONShapes(t *testing.T) {
16541657
if action := keymap.Resolve(ParseKey("\x17")); action != ActionDeleteWordBack {
16551658
t.Fatalf("shortcutKey override action = %q", action)
16561659
}
1660+
if action := keymap.Resolve(ParseKey("\x11")); action != ActionPageUp {
1661+
t.Fatalf("accelerator override action = %q", action)
1662+
}
1663+
if action := keymap.Resolve(ParseKey("\x16")); action != ActionPageDown {
1664+
t.Fatalf("keystroke override action = %q", action)
1665+
}
1666+
if action := keymap.Resolve(ParseKey("\x1a")); action != ActionRedraw {
1667+
t.Fatalf("hotKey override action = %q", action)
1668+
}
16571669
}
16581670

16591671
func TestParseKeyBindingSpecsAcceptsNestedWrappers(t *testing.T) {

0 commit comments

Comments
 (0)