Skip to content

Commit 84794b8

Browse files
committed
Record return in shared enter detection
1 parent 920ff45 commit 84794b8

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

cli/src/utils/__tests__/terminal-enter-detection.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ describe('terminal enter detection', () => {
5858
expect(isPlainEnterKey({ name: '', sequence: '\x1bOM' })).toBe(true)
5959
})
6060

61+
test('plain Enter detection records return before later linefeed checks', () => {
62+
expect(isLinefeedActingAsEnter()).toBe(true)
63+
expect(isPlainEnterKey({ name: 'return', sequence: '\r' })).toBe(true)
64+
expect(isLinefeedActingAsEnter()).toBe(false)
65+
expect(isPlainEnterKey({ name: 'linefeed', sequence: '\n' })).toBe(false)
66+
})
67+
6168
test('does not recognize modified keypad Enter as plain Enter', () => {
6269
expect(
6370
isPlainEnterKey({

cli/src/utils/terminal-enter-detection.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export function shouldMarkReturnKeySeen(key: EnterDetectionKey): boolean {
2525
}
2626

2727
export function isPlainEnterKey(key: EnterDetectionKey): boolean {
28+
// Some local interceptors consume Enter before the global keyboard hooks see
29+
// it, so record non-keypad Return here before consulting the linefeed fallback.
30+
markReturnKeySeenForKey(key)
31+
2832
return (
2933
(key.name === 'return' ||
3034
key.name === 'enter' ||

0 commit comments

Comments
 (0)