fix(cli): resolve Ctrl+Enter and Ctrl+J newline issues (#17021)

This commit is contained in:
imadraude
2026-01-20 23:56:33 +02:00
committed by GitHub
parent 67d69084e9
commit 645e2ec041
2 changed files with 33 additions and 3 deletions

View File

@@ -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', () => {

View File

@@ -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