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

View File

@@ -80,8 +80,8 @@ describe('KeyBinding', () => {
});
it('should handle named keys with modifiers', () => {
const binding = new KeyBinding('ctrl+return');
expect(binding.key).toBe('return');
const binding = new KeyBinding('ctrl+enter');
expect(binding.key).toBe('enter');
expect(binding.ctrl).toBe(true);
});

View File

@@ -149,11 +149,9 @@ export class KeyBinding {
'numpad_subtract',
'numpad_decimal',
'numpad_divide',
// Gemini CLI legacy/internal support
'return',
]);
/** The key name (e.g., 'a', 'return', 'tab', 'escape') */
/** The key name (e.g., 'a', 'enter', 'tab', 'escape') */
readonly key: string;
readonly shift: boolean;
readonly alt: boolean;
@@ -238,7 +236,7 @@ export type KeyBindingConfig = {
*/
export const defaultKeyBindings: KeyBindingConfig = {
// Basic Controls
[Command.RETURN]: [new KeyBinding('return')],
[Command.RETURN]: [new KeyBinding('enter')],
[Command.ESCAPE]: [new KeyBinding('escape'), new KeyBinding('ctrl+[')],
[Command.QUIT]: [new KeyBinding('ctrl+c')],
[Command.EXIT]: [new KeyBinding('ctrl+d')],
@@ -308,7 +306,7 @@ export const defaultKeyBindings: KeyBindingConfig = {
[Command.HISTORY_UP]: [new KeyBinding('ctrl+p')],
[Command.HISTORY_DOWN]: [new KeyBinding('ctrl+n')],
[Command.REVERSE_SEARCH]: [new KeyBinding('ctrl+r')],
[Command.SUBMIT_REVERSE_SEARCH]: [new KeyBinding('return')],
[Command.SUBMIT_REVERSE_SEARCH]: [new KeyBinding('enter')],
[Command.ACCEPT_SUGGESTION_REVERSE_SEARCH]: [new KeyBinding('tab')],
// Navigation
@@ -325,10 +323,7 @@ export const defaultKeyBindings: KeyBindingConfig = {
[Command.DIALOG_PREV]: [new KeyBinding('shift+tab')],
// Suggestions & Completions
[Command.ACCEPT_SUGGESTION]: [
new KeyBinding('tab'),
new KeyBinding('return'),
],
[Command.ACCEPT_SUGGESTION]: [new KeyBinding('tab'), new KeyBinding('enter')],
[Command.COMPLETION_UP]: [new KeyBinding('up'), new KeyBinding('ctrl+p')],
[Command.COMPLETION_DOWN]: [new KeyBinding('down'), new KeyBinding('ctrl+n')],
[Command.EXPAND_SUGGESTION]: [new KeyBinding('right')],
@@ -336,12 +331,12 @@ export const defaultKeyBindings: KeyBindingConfig = {
// Text Input
// Must also exclude shift to allow shift+enter for newline
[Command.SUBMIT]: [new KeyBinding('return')],
[Command.SUBMIT]: [new KeyBinding('enter')],
[Command.NEWLINE]: [
new KeyBinding('ctrl+return'),
new KeyBinding('cmd+return'),
new KeyBinding('alt+return'),
new KeyBinding('shift+return'),
new KeyBinding('ctrl+enter'),
new KeyBinding('cmd+enter'),
new KeyBinding('alt+enter'),
new KeyBinding('shift+enter'),
new KeyBinding('ctrl+j'),
],
[Command.OPEN_EXTERNAL_EDITOR]: [new KeyBinding('ctrl+x')],
@@ -366,7 +361,7 @@ export const defaultKeyBindings: KeyBindingConfig = {
[Command.UNFOCUS_BACKGROUND_SHELL_LIST]: [new KeyBinding('tab')],
[Command.SHOW_BACKGROUND_SHELL_UNFOCUS_WARNING]: [new KeyBinding('tab')],
[Command.SHOW_SHELL_INPUT_UNFOCUS_WARNING]: [new KeyBinding('tab')],
[Command.BACKGROUND_SHELL_SELECT]: [new KeyBinding('return')],
[Command.BACKGROUND_SHELL_SELECT]: [new KeyBinding('enter')],
[Command.BACKGROUND_SHELL_ESCAPE]: [new KeyBinding('escape')],
[Command.SHOW_MORE_LINES]: [new KeyBinding('ctrl+o')],
[Command.EXPAND_PASTE]: [new KeyBinding('ctrl+o')],

View File

@@ -31,7 +31,7 @@ describe('keyMatchers', () => {
// Basic bindings
{
command: Command.RETURN,
positive: [createKey('return')],
positive: [createKey('enter')],
negative: [createKey('r')],
},
{
@@ -270,8 +270,8 @@ describe('keyMatchers', () => {
// Auto-completion
{
command: Command.ACCEPT_SUGGESTION,
positive: [createKey('tab'), createKey('return')],
negative: [createKey('return', { ctrl: true }), createKey('space')],
positive: [createKey('tab'), createKey('enter')],
negative: [createKey('enter', { ctrl: true }), createKey('space')],
},
{
command: Command.COMPLETION_UP,
@@ -287,21 +287,21 @@ describe('keyMatchers', () => {
// Text input
{
command: Command.SUBMIT,
positive: [createKey('return')],
positive: [createKey('enter')],
negative: [
createKey('return', { ctrl: true }),
createKey('return', { cmd: true }),
createKey('return', { alt: true }),
createKey('enter', { ctrl: true }),
createKey('enter', { cmd: true }),
createKey('enter', { alt: true }),
],
},
{
command: Command.NEWLINE,
positive: [
createKey('return', { ctrl: true }),
createKey('return', { cmd: true }),
createKey('return', { alt: true }),
createKey('enter', { ctrl: true }),
createKey('enter', { cmd: true }),
createKey('enter', { alt: true }),
],
negative: [createKey('return'), createKey('n')],
negative: [createKey('enter'), createKey('n')],
},
// External tools
@@ -382,14 +382,14 @@ describe('keyMatchers', () => {
},
{
command: Command.SUBMIT_REVERSE_SEARCH,
positive: [createKey('return')],
negative: [createKey('return', { ctrl: true }), createKey('tab')],
positive: [createKey('enter')],
negative: [createKey('enter', { ctrl: true }), createKey('tab')],
},
{
command: Command.ACCEPT_SUGGESTION_REVERSE_SEARCH,
positive: [createKey('tab')],
negative: [
createKey('return'),
createKey('enter'),
createKey('space'),
createKey('tab', { ctrl: true }),
],

View File

@@ -21,7 +21,7 @@ const SPECIAL_KEYS: Record<string, string> = {
end: '\x1b[F',
pageup: '\x1b[5~',
pagedown: '\x1b[6~',
return: '\r',
enter: '\r',
};
/**

View File

@@ -27,7 +27,7 @@ describe('keybindingUtils', () => {
},
{
name: 'named key (return)',
binding: new KeyBinding('return'),
binding: new KeyBinding('enter'),
expected: {
darwin: 'Enter',
win32: 'Enter',

View File

@@ -16,7 +16,7 @@ import {
* Maps internal key names to user-friendly display names.
*/
const KEY_NAME_MAP: Record<string, string> = {
return: 'Enter',
enter: 'Enter',
escape: 'Esc',
backspace: 'Backspace',
delete: 'Delete',