Skip to content

fix: vim keys crash with emitKeys error on Node.js v25#15

Merged
m1ngsama merged 1 commit intomainfrom
fix/vim-keys-node25-emitkeys-crash
Mar 2, 2026
Merged

fix: vim keys crash with emitKeys error on Node.js v25#15
m1ngsama merged 1 commit intomainfrom
fix/vim-keys-node25-emitkeys-crash

Conversation

@m1ngsama
Copy link
Member

@m1ngsama m1ngsama commented Mar 2, 2026

Closes #14

Summary

  • Root cause: stdin.emit patch re-emitted synthetic keypress events with incomplete key objects; Node.js v25 routes these back through ReadStream.onData → emitKeys generator, which crashes
  • Fix: Intercept at the raw data layer — replace vim key bytes with terminal escape sequences before readline processes them
  • Result: readline's emitKeys receives valid sequences and generates correct keypress events naturally, no crash

Changes

src/core/vim-keys.ts — switched from keypress interception to data interception:

Before: stdin.emit patch → intercept 'keypress' → re-emit synthetic keypress
After:  stdin.emit patch → intercept 'data' → replace byte with escape sequence
Key Escape Sequence
j \u001b[B (↓)
k \u001b[A (↑)
g \u001b[H (Home)
G \u001b[F (End)
q \u0003 (Ctrl+C)

Test plan

  • npm run build — clean compile
  • node dist/index.js --help — script mode works
  • node dist/index.js events --json — backward compat intact
  • Manual: launch interactive menu, verify j/k navigation works on Node.js v25

The previous approach patched stdin.emit and re-emitted synthetic keypress
events with partial key objects. In Node.js v25, readline's internal
architecture changed such that synthetic keypress events route back through
ReadStream.onData → emitKeys generator, crashing on incomplete key data.

Fix by intercepting at the raw data layer: replace single-byte vim keys
(j/k/g/G/q) with their terminal escape sequences before readline processes
them. readline's emitKeys generator receives valid escape sequences and
produces correct keypress events naturally.

Fixes #14
@m1ngsama m1ngsama merged commit f24db04 into main Mar 2, 2026
2 checks passed
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.

fix: vim keys crash with emitKeys error on Node.js v25

1 participant