Skip to content

Commit

Permalink
readline: emit key info unconditionally
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cjihrig committed Apr 5, 2016
1 parent 3de9bc9 commit 0a62f92
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/internal/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,8 @@ function* emitKeys(stream) {
stream.emit('keypress', escaped ? undefined : s, key);
} else if (s.length === 1) {
/* Single unnamed character, e.g. "." */
stream.emit('keypress', s);
} else {
/* Unrecognized or broken escape sequence, don't emit anything */
stream.emit('keypress', s, key);
}
/* Unrecognized or broken escape sequence, don't emit anything */
}
}
2 changes: 1 addition & 1 deletion test/parallel/test-readline-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function addTest(sequences, expectedKeys) {
addTest('io.JS', [
{ name: 'i', sequence: 'i' },
{ name: 'o', sequence: 'o' },
undefined, // emitted as `emit('keypress', '.', undefined)`
{ name: undefined, sequence: '.' },
{ name: 'j', sequence: 'J', shift: true },
{ name: 's', sequence: 'S', shift: true },
]);
Expand Down

0 comments on commit 0a62f92

Please sign in to comment.