Skip to content

Commit 9a8ff4f

Browse files
author
SqlRush
committed
Replay punctuation script key codes
1 parent 51a990c commit 9a8ff4f

5 files changed

Lines changed: 41 additions & 7 deletions

File tree

docs/cc-100-roadmap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ M7 补充:prompt history `LogEntry` 读取现在接受 `sessionID`/`session`/`
730730

731731
本轮补充:prompt history 读取旧 image pasted-content 记录时,如果缺少 source path 但对应 session 的 image-cache 文件仍存在,会自动补回 source path 并刷新内存 image path cache。
732732

733-
本轮补充:interaction script key 字段现在接受 DOM-style key event object,可从 `key`/`code`(包括 `Numpad*` code)、旧式 `keyIdentifier`、数字 `keyCode`/`which`/`charCode``keypress.which` 字符码、`ctrlKey`/`altKey`/`metaKey`/`shiftKey``modifiers` 数组还原现有 key 名,wrapper payload 中的 key event 也可驱动脚本回放。
733+
本轮补充:interaction script key 字段现在接受 DOM-style key event object,可从 `key`/`code`(包括 `Numpad*` 和标点 key code)、旧式 `keyIdentifier`、数字 `keyCode`/`which`/`charCode``keypress.which` 字符码、`ctrlKey`/`altKey`/`metaKey`/`shiftKey``modifiers` 数组还原现有 key 名,wrapper payload 中的 key event 也可驱动脚本回放。
734734

735735
本轮补充:interaction script mouse payload 现在可从 `mouseup``pointerUp``touchend` 等 event type 推导 release 状态;显式 release bool 仍优先生效。
736736

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ test/parity/ # golden tests against TS/official behavior
232232
- 本轮补充:TUI Vim prompt editing 增加基础 visual/visual-line 模式,支持 `v`/`V` 进入选择、motion 扩展 selection、`y`/`d`/`c` 作用于选择范围、Esc 回到 normal,并让 interaction script 可用 `visual`/`visualLine` 断言当前 mode。
233233
- 本轮补充:prompt history 写入现在保留 image pasted-content 的 media type、filename、dimensions 和 image-cache source path 元数据,同时继续不把 inline base64 image bytes 或 text-paste hash 写进图片历史记录。
234234
- 本轮补充:prompt history 读取旧 image pasted-content 记录时,如果缺少 source path 但对应 session 的 image-cache 文件仍存在,会自动补回 source path 并刷新内存 image path cache。
235-
- 本轮补充:interaction script key 字段现在接受 DOM-style key event object,可从 `key`/`code`(包括 `Numpad*` code)、旧式 `keyIdentifier`、数字 `keyCode`/`which`/`charCode``keypress.which` 字符码、`ctrlKey`/`altKey`/`metaKey`/`shiftKey``modifiers` 数组还原现有 key 名,wrapper payload 中的 key event 也可驱动脚本回放。
235+
- 本轮补充:interaction script key 字段现在接受 DOM-style key event object,可从 `key`/`code`(包括 `Numpad*` 和标点 key code)、旧式 `keyIdentifier`、数字 `keyCode`/`which`/`charCode``keypress.which` 字符码、`ctrlKey`/`altKey`/`metaKey`/`shiftKey``modifiers` 数组还原现有 key 名,wrapper payload 中的 key event 也可驱动脚本回放。
236236
- 本轮补充:interaction script mouse payload 现在可从 `mouseup``pointerUp``touchend` 等 event type 推导 release 状态;显式 release bool 仍优先生效。
237237
- 本轮补充:interaction script mouse payload 现在可从 `wheel`/`mousewheel``scrollUp`/`scrollDown``direction``deltaY` 和旧式 `wheelDelta` 推导 SGR wheel button,录制的 DOM/compact 滚轮事件可直接驱动 viewport 滚动。
238238
- 本轮补充:interaction script mouse payload 现在接受 DOM `which``buttons`/`buttonState` bitmask,并映射到 SGR left/middle/right button,避免录制脚本的右键/中键被误当成 primary click。

docs/first-second-parity-audit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ M7 progress now includes:
228228
- `internal/tui`: Vim prompt editing now includes basic visual and visual-line mode support with `v`/`V`, motion-extended selections, `y`/`d`/`c` range operators, Escape return-to-normal behavior, and script expectation aliases for `visual`/`visualLine` modes.
229229
- `internal/session`: prompt history now persists image pasted-content metadata such as media type, filename, dimensions, and image-cache source path while still omitting inline base64 image bytes and text-paste hashes for images.
230230
- `internal/session`: prompt history loading now backfills missing image source paths from existing per-session image-cache files and refreshes the in-memory image path cache when those files exist.
231-
- `internal/tui`: interaction script key fields now accept DOM-style key event objects with `key`/`code` including `Numpad*` codes, legacy `keyIdentifier`, numeric `keyCode`/`which`/`charCode`, `keypress.which` char-code replay, modifier booleans such as `ctrlKey`/`altKey`/`metaKey`/`shiftKey`, and modifier arrays, including wrapper payloads and modifier-only event filtering.
231+
- `internal/tui`: interaction script key fields now accept DOM-style key event objects with `key`/`code` including `Numpad*` and punctuation key codes, legacy `keyIdentifier`, numeric `keyCode`/`which`/`charCode`, `keypress.which` char-code replay, modifier booleans such as `ctrlKey`/`altKey`/`metaKey`/`shiftKey`, and modifier arrays, including wrapper payloads and modifier-only event filtering.
232232
- `internal/tui`: interaction script mouse payloads now infer release state from event type aliases such as `mouseup`, `pointerUp`, and `touchend`, while explicit release booleans still take precedence.
233233
- `internal/tui`: interaction script mouse payloads now infer SGR wheel buttons from DOM/compact wheel inputs such as `wheel`, `mousewheel`, `scrollUp`/`scrollDown`, `direction`, `deltaY`, and legacy `wheelDelta`, allowing recorded wheel events to drive viewport scrolling.
234234
- `internal/tui`: interaction script mouse payloads now accept DOM `which` and `buttons`/`buttonState` bitmasks and map them to SGR left/middle/right buttons so recorded secondary or auxiliary clicks are not treated as primary clicks.

internal/tui/script_aliases.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3136,6 +3136,9 @@ func scriptKeyEventBaseName(key string) (string, bool) {
31363136
case "space", "spacebar":
31373137
return " ", false
31383138
}
3139+
if base, ok := scriptDOMCodeBaseName(normalized); ok {
3140+
return base, false
3141+
}
31393142
if base, ok := scriptNumpadKeyBaseName(normalized); ok {
31403143
return base, false
31413144
}
@@ -3151,6 +3154,35 @@ func scriptKeyEventBaseName(key string) (string, bool) {
31513154
return trimmed, false
31523155
}
31533156

3157+
func scriptDOMCodeBaseName(normalized string) (string, bool) {
3158+
switch normalized {
3159+
case "backquote":
3160+
return "`", true
3161+
case "minus":
3162+
return "-", true
3163+
case "equal":
3164+
return "=", true
3165+
case "bracketleft", "bracket-left":
3166+
return "[", true
3167+
case "bracketright", "bracket-right":
3168+
return "]", true
3169+
case "backslash", "intlbackslash", "intl-backslash":
3170+
return "\\", true
3171+
case "semicolon":
3172+
return ";", true
3173+
case "quote":
3174+
return "'", true
3175+
case "comma":
3176+
return ",", true
3177+
case "period":
3178+
return ".", true
3179+
case "slash":
3180+
return "/", true
3181+
default:
3182+
return "", false
3183+
}
3184+
}
3185+
31543186
func scriptNumpadKeyBaseName(normalized string) (string, bool) {
31553187
suffix, ok := strings.CutPrefix(normalized, "numpad")
31563188
if !ok {

internal/tui/tui_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6195,6 +6195,7 @@ func TestRunInteractionScriptAcceptsKeyEventObjects(t *testing.T) {
61956195
{"keys":[{"keyIdentifier":"U+0061"},{"key_identifier":"U+0020"},{"keyIdentifier":"U+0062","shiftKey":true},{"keyIdentifier":"Enter"}],"expectEvent":{"type":"prompt_submitted","value":"a B"},"expectPrompt":{"empty":true}},
61966196
{"keys":[{"type":"keypress","which":33},{"eventType":"keypress","which":65},{"name":"keypress","which":32},{"keyCode":13}],"expectEvent":{"type":"prompt_submitted","value":"!A "},"expectPrompt":{"empty":true}},
61976197
{"keys":[{"code":"Numpad1"},{"code":"NumpadAdd"},{"code":"Numpad2"},{"code":"NumpadDecimal"},{"code":"NumpadEnter"}],"expectEvent":{"type":"prompt_submitted","value":"1+2."},"expectPrompt":{"empty":true}},
6198+
{"keys":[{"code":"Minus"},{"code":"Equal"},{"code":"BracketLeft"},{"code":"BracketRight"},{"code":"Backslash"},{"code":"Semicolon"},{"code":"Quote"},{"code":"Comma"},{"code":"Period"},{"code":"Slash"},{"key":"Enter"}],"expectEvent":{"type":"prompt_submitted","value":"-=[]\\;',./"},"expectPrompt":{"empty":true}},
61986199
{"keys":[{"keyCode":17,"ctrlKey":true},{"keyCode":88,"ctrlKey":true},{"which":75,"ctrlKey":true}],"expectEvent":{"type":"kill_agents"}},
61996200
{"kind":"keys","data":[{"code":"KeyO"},{"code":"Digit1"},{"key":"Enter"}],"expectEvent":{"type":"prompt_submitted","value":"o1"},"expectPrompt":{"empty":true}},
62006201
{"keys":[{"key":"x","modifiers":["ctrl"]},{"key":"k","modifiers":["control"]}],"expectEvent":{"type":"kill_agents"}},
@@ -6208,15 +6209,16 @@ func TestRunInteractionScriptAcceptsKeyEventObjects(t *testing.T) {
62086209
if err != nil {
62096210
t.Fatal(err)
62106211
}
6211-
if len(result.Events) != 8 ||
6212+
if len(result.Events) != 9 ||
62126213
result.Events[0].Type != ScreenEventPromptSubmitted || result.Events[0].Value != "hi" ||
62136214
result.Events[1].Type != ScreenEventPromptSubmitted || result.Events[1].Value != "hi !" ||
62146215
result.Events[2].Type != ScreenEventPromptSubmitted || result.Events[2].Value != "a B" ||
62156216
result.Events[3].Type != ScreenEventPromptSubmitted || result.Events[3].Value != "!A " ||
62166217
result.Events[4].Type != ScreenEventPromptSubmitted || result.Events[4].Value != "1+2." ||
6217-
result.Events[5].Type != ScreenEventKillAgents ||
6218-
result.Events[6].Type != ScreenEventPromptSubmitted || result.Events[6].Value != "o1" ||
6219-
result.Events[7].Type != ScreenEventKillAgents {
6218+
result.Events[5].Type != ScreenEventPromptSubmitted || result.Events[5].Value != "-=[]\\;',./" ||
6219+
result.Events[6].Type != ScreenEventKillAgents ||
6220+
result.Events[7].Type != ScreenEventPromptSubmitted || result.Events[7].Value != "o1" ||
6221+
result.Events[8].Type != ScreenEventKillAgents {
62206222
t.Fatalf("events = %#v", result.Events)
62216223
}
62226224
}

0 commit comments

Comments
 (0)