diff --git a/packages/cli/src/ui/contexts/KeypressContext.test.tsx b/packages/cli/src/ui/contexts/KeypressContext.test.tsx index af707fff69..c557706b64 100644 --- a/packages/cli/src/ui/contexts/KeypressContext.test.tsx +++ b/packages/cli/src/ui/contexts/KeypressContext.test.tsx @@ -154,6 +154,36 @@ describe('KeypressContext', () => { ); }, ); + + it('should recognize \n (LF) as ctrl+j', async () => { + const { keyHandler } = setupKeypressTest(); + + act(() => stdin.write('\n')); + + expect(keyHandler).toHaveBeenCalledWith( + expect.objectContaining({ + name: 'j', + ctrl: true, + meta: false, + shift: false, + }), + ); + }); + + it('should recognize \\x1b\\n as Alt+Enter (return with meta)', async () => { + const { keyHandler } = setupKeypressTest(); + + act(() => stdin.write('\x1b\n')); + + expect(keyHandler).toHaveBeenCalledWith( + expect.objectContaining({ + name: 'return', + ctrl: false, + meta: true, + shift: false, + }), + ); + }); }); describe('Fast return buffering', () => { diff --git a/packages/cli/src/ui/contexts/KeypressContext.tsx b/packages/cli/src/ui/contexts/KeypressContext.tsx index 4fc774a00b..88aad71a27 100644 --- a/packages/cli/src/ui/contexts/KeypressContext.tsx +++ b/packages/cli/src/ui/contexts/KeypressContext.tsx @@ -524,9 +524,9 @@ function* emitKeys( // carriage return name = 'return'; meta = escaped; - } else if (ch === '\n') { - // Enter, should have been called linefeed - name = 'enter'; + } else if (escaped && ch === '\n') { + // Alt+Enter (linefeed), should be consistent with carriage return + name = 'return'; meta = escaped; } else if (ch === '\t') { // tab