Skip to content

Commit 0a62f92

Browse files
committed
readline: emit key info unconditionally
Currently, 'keypress' events include the sequence and key info for named keys, but only the sequence for unnamed keys. This commit causes the key info to be included in both cases. PR-URL: #6024 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
1 parent 3de9bc9 commit 0a62f92

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

lib/internal/readline.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,8 @@ function* emitKeys(stream) {
384384
stream.emit('keypress', escaped ? undefined : s, key);
385385
} else if (s.length === 1) {
386386
/* Single unnamed character, e.g. "." */
387-
stream.emit('keypress', s);
388-
} else {
389-
/* Unrecognized or broken escape sequence, don't emit anything */
387+
stream.emit('keypress', s, key);
390388
}
389+
/* Unrecognized or broken escape sequence, don't emit anything */
391390
}
392391
}

test/parallel/test-readline-keys.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function addTest(sequences, expectedKeys) {
4848
addTest('io.JS', [
4949
{ name: 'i', sequence: 'i' },
5050
{ name: 'o', sequence: 'o' },
51-
undefined, // emitted as `emit('keypress', '.', undefined)`
51+
{ name: undefined, sequence: '.' },
5252
{ name: 'j', sequence: 'J', shift: true },
5353
{ name: 's', sequence: 'S', shift: true },
5454
]);

0 commit comments

Comments
 (0)