Skip to content

Commit 104ebbc

Browse files
committed
fix(input): set printable sequence for modifyOtherKeys chars
modifyOtherKeys (CSI 27;mod;code~) currently decodes name and modifiers but leaves sequence as the raw ESC sequence. Textarea inserts from sequence and rejects control chars (< 32), so sequences like ESC [27;2;49~ (Shift+1 on AZERTY in WezTerm) never insert text. Terminals that send plain "1" take the single-byte digit path and work. For printable codes, set sequence to the decoded character and mark digits as number=true. This mirrors the single-byte digit behavior, so text insertion now sees "1" instead of ESC and passes the guard. Raw is preserved and special keys (return/escape/tab/space/backspace) still keep their raw sequences, so control/navigation handling does not change. Keybinding lookup continues to use name+modifiers, so shortcuts are unaffected. This addresses an issue reported in opencode anomalyco/opencode#10577
1 parent 57ddb7f commit 104ebbc

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎packages/core/src/lib/parse.keypress.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,20 @@ test("parseKeypress - fallback to raw parsing when Kitty option is enabled but s
15011501
expect(normalCtrl?.ctrl).toBe(true)
15021502
})
15031503

1504+
test("parseKeypress - modifyOtherKeys digits", () => {
1505+
const shiftOne = parseKeypress("\x1b[27;2;49~")!
1506+
expect(shiftOne.name).toBe("1")
1507+
expect(shiftOne.shift).toBe(true)
1508+
expect(shiftOne.ctrl).toBe(false)
1509+
expect(shiftOne.meta).toBe(false)
1510+
expect(shiftOne.option).toBe(false)
1511+
expect(shiftOne.number).toBe(true)
1512+
expect(shiftOne.sequence).toBe("1")
1513+
expect(shiftOne.raw).toBe("\x1b[27;2;49~")
1514+
expect(shiftOne.eventType).toBe("press")
1515+
expect(shiftOne.source).toBe("raw")
1516+
})
1517+
15041518
test("parseKeypress - modifyOtherKeys modified enter keys", () => {
15051519
// Terminals with modifyOtherKeys mode enabled send special escape sequences for modified keys
15061520
// Format: CSI 27 ; modifier ; code ~ where code 13 is enter/return

‎packages/core/src/lib/parse.keypress.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,12 @@ export const parseKeypress = (s: Buffer | string = "", options: ParseKeypressOpt
250250
key.name = "backspace"
251251
} else {
252252
// For other character codes, use the character itself
253-
key.name = String.fromCharCode(charCode)
253+
const char = String.fromCharCode(charCode)
254+
key.name = char
255+
key.sequence = char
256+
if (charCode >= 48 && charCode <= 57) {
257+
key.number = true
258+
}
254259
}
255260

256261
return key

0 commit comments

Comments
 (0)