migrate yolo/auto-edit keybindings (#16457)

This commit is contained in:
Tommaso Sciortino
2026-01-12 14:50:32 -08:00
committed by GitHub
parent b8cc414d5b
commit 95d9a33996
4 changed files with 34 additions and 13 deletions
+8
View File
@@ -62,6 +62,8 @@ export enum Command {
TOGGLE_IDE_CONTEXT_DETAIL = 'toggleIDEContextDetail',
TOGGLE_MARKDOWN = 'toggleMarkdown',
TOGGLE_COPY_MODE = 'toggleCopyMode',
TOGGLE_YOLO = 'toggleYolo',
TOGGLE_AUTO_EDIT = 'toggleAutoEdit',
QUIT = 'quit',
EXIT = 'exit',
SHOW_MORE_LINES = 'showMoreLines',
@@ -203,6 +205,8 @@ export const defaultKeyBindings: KeyBindingConfig = {
[Command.TOGGLE_IDE_CONTEXT_DETAIL]: [{ key: 'g', ctrl: true }],
[Command.TOGGLE_MARKDOWN]: [{ key: 'm', command: true }],
[Command.TOGGLE_COPY_MODE]: [{ key: 's', ctrl: true }],
[Command.TOGGLE_YOLO]: [{ key: 'y', ctrl: true }],
[Command.TOGGLE_AUTO_EDIT]: [{ key: 'tab', shift: true }],
[Command.QUIT]: [{ key: 'c', ctrl: true }],
[Command.EXIT]: [{ key: 'd', ctrl: true }],
[Command.SHOW_MORE_LINES]: [{ key: 's', ctrl: true }],
@@ -305,6 +309,8 @@ export const commandCategories: readonly CommandCategory[] = [
Command.TOGGLE_IDE_CONTEXT_DETAIL,
Command.TOGGLE_MARKDOWN,
Command.TOGGLE_COPY_MODE,
Command.TOGGLE_YOLO,
Command.TOGGLE_AUTO_EDIT,
Command.SHOW_MORE_LINES,
Command.TOGGLE_SHELL_INPUT_FOCUS,
],
@@ -354,6 +360,8 @@ export const commandDescriptions: Readonly<Record<Command, string>> = {
[Command.TOGGLE_MARKDOWN]: 'Toggle Markdown rendering.',
[Command.TOGGLE_COPY_MODE]:
'Toggle copy mode when the terminal is using the alternate buffer.',
[Command.TOGGLE_YOLO]: 'Toggle YOLO (auto-approval) mode for tool calls.',
[Command.TOGGLE_AUTO_EDIT]: 'Toggle Auto Edit (auto-accept edits) mode.',
[Command.QUIT]: 'Cancel the current request or quit the CLI.',
[Command.EXIT]: 'Exit the CLI when the input buffer is empty.',
[Command.SHOW_MORE_LINES]:
@@ -7,6 +7,7 @@
import { useState, useEffect } from 'react';
import { ApprovalMode, type Config } from '@google/gemini-cli-core';
import { useKeypress } from './useKeypress.js';
import { keyMatchers, Command } from '../keyMatchers.js';
import type { HistoryItemWithoutId } from '../types.js';
import { MessageType } from '../types.js';
@@ -33,7 +34,7 @@ export function useAutoAcceptIndicator({
(key) => {
let nextApprovalMode: ApprovalMode | undefined;
if (key.ctrl && key.name === 'y') {
if (keyMatchers[Command.TOGGLE_YOLO](key)) {
if (
config.isYoloModeDisabled() &&
config.getApprovalMode() !== ApprovalMode.YOLO
@@ -53,7 +54,7 @@ export function useAutoAcceptIndicator({
config.getApprovalMode() === ApprovalMode.YOLO
? ApprovalMode.DEFAULT
: ApprovalMode.YOLO;
} else if (key.shift && key.name === 'tab') {
} else if (keyMatchers[Command.TOGGLE_AUTO_EDIT](key)) {
nextApprovalMode =
config.getApprovalMode() === ApprovalMode.AUTO_EDIT
? ApprovalMode.DEFAULT
+12
View File
@@ -77,6 +77,8 @@ describe('keyMatchers', () => {
key.name === 'tab',
[Command.TOGGLE_SHELL_INPUT_FOCUS]: (key: Key) =>
key.ctrl && key.name === 'f',
[Command.TOGGLE_YOLO]: (key: Key) => key.ctrl && key.name === 'y',
[Command.TOGGLE_AUTO_EDIT]: (key: Key) => key.shift && key.name === 'tab',
[Command.EXPAND_SUGGESTION]: (key: Key) => key.name === 'right',
[Command.COLLAPSE_SUGGESTION]: (key: Key) => key.name === 'left',
};
@@ -336,6 +338,16 @@ describe('keyMatchers', () => {
positive: [createKey('f', { ctrl: true })],
negative: [createKey('f')],
},
{
command: Command.TOGGLE_YOLO,
positive: [createKey('y', { ctrl: true })],
negative: [createKey('y'), createKey('y', { meta: true })],
},
{
command: Command.TOGGLE_AUTO_EDIT,
positive: [createKey('tab', { shift: true })],
negative: [createKey('tab')],
},
];
describe('Data-driven key binding matches original logic', () => {