refactor(cli): rename 'return' key to 'enter' internally (#21796)

This commit is contained in:
Tommaso Sciortino
2026-03-10 02:32:40 +00:00
committed by GitHub
parent ec7773eb7b
commit 14412c3a72
19 changed files with 67 additions and 72 deletions
@@ -100,7 +100,7 @@ describe('KeypressContext', () => {
expect(keyHandler).toHaveBeenCalledWith(
expect.objectContaining({
name: 'return',
name: 'enter',
shift: false,
ctrl: false,
cmd: false,
@@ -115,7 +115,7 @@ describe('KeypressContext', () => {
expect(keyHandler).toHaveBeenCalledWith(
expect.objectContaining({
name: 'return',
name: 'enter',
shift: true,
ctrl: false,
cmd: false,
@@ -148,7 +148,7 @@ describe('KeypressContext', () => {
expect(keyHandler).toHaveBeenCalledWith(
expect.objectContaining({
name: 'return',
name: 'enter',
...expected,
}),
);
@@ -177,7 +177,7 @@ describe('KeypressContext', () => {
expect(keyHandler).toHaveBeenCalledWith(
expect.objectContaining({
name: 'return',
name: 'enter',
shift: false,
alt: true,
ctrl: false,
@@ -216,7 +216,7 @@ describe('KeypressContext', () => {
expect(keyHandler).toHaveBeenLastCalledWith(
expect.objectContaining({
name: 'return',
name: 'enter',
sequence: '\r',
insertable: true,
shift: true,
@@ -238,7 +238,7 @@ describe('KeypressContext', () => {
expect(keyHandler).toHaveBeenLastCalledWith(
expect.objectContaining({
name: 'return',
name: 'enter',
shift: false,
alt: false,
ctrl: false,
@@ -638,8 +638,8 @@ describe('KeypressContext', () => {
describe('Parameterized functional keys', () => {
it.each([
// ModifyOtherKeys
{ sequence: `\x1b[27;2;13~`, expected: { name: 'return', shift: true } },
{ sequence: `\x1b[27;5;13~`, expected: { name: 'return', ctrl: true } },
{ sequence: `\x1b[27;2;13~`, expected: { name: 'enter', shift: true } },
{ sequence: `\x1b[27;5;13~`, expected: { name: 'enter', ctrl: true } },
{ sequence: `\x1b[27;5;9~`, expected: { name: 'tab', ctrl: true } },
{
sequence: `\x1b[27;6;9~`,
@@ -1124,7 +1124,7 @@ describe('KeypressContext', () => {
expect(keyHandler).toHaveBeenNthCalledWith(
1,
expect.objectContaining({
name: 'return',
name: 'enter',
}),
);
expect(keyHandler).toHaveBeenNthCalledWith(
@@ -92,11 +92,11 @@ const KEY_INFO_MAP: Record<
'[[5~': { name: 'pageup' },
'[[6~': { name: 'pagedown' },
'[9u': { name: 'tab' },
'[13u': { name: 'return' },
'[13u': { name: 'enter' },
'[27u': { name: 'escape' },
'[32u': { name: 'space' },
'[127u': { name: 'backspace' },
'[57414u': { name: 'return' }, // Numpad Enter
'[57414u': { name: 'enter' }, // Numpad Enter
'[a': { name: 'up', shift: true },
'[b': { name: 'down', shift: true },
'[c': { name: 'right', shift: true },
@@ -186,10 +186,10 @@ function bufferFastReturn(keypressHandler: KeypressHandler): KeypressHandler {
let lastKeyTime = 0;
return (key: Key) => {
const now = Date.now();
if (key.name === 'return' && now - lastKeyTime <= FAST_RETURN_TIMEOUT) {
if (key.name === 'enter' && now - lastKeyTime <= FAST_RETURN_TIMEOUT) {
keypressHandler({
...key,
name: 'return',
name: 'enter',
shift: true, // to make it a newline, not a submission
alt: false,
ctrl: false,
@@ -232,7 +232,7 @@ function bufferBackslashEnter(
if (nextKey === null) {
keypressHandler(key);
} else if (nextKey.name === 'return') {
} else if (nextKey.name === 'enter') {
keypressHandler({
...nextKey,
shift: true,
@@ -582,11 +582,11 @@ function* emitKeys(
}
} else if (ch === '\r') {
// carriage return
name = 'return';
name = 'enter';
alt = escaped;
} else if (escaped && ch === '\n') {
// Alt+Enter (linefeed), should be consistent with carriage return
name = 'return';
name = 'enter';
alt = escaped;
} else if (ch === '\t') {
// tab