From 95d9a339966b6d594bddc2ed649b2348f1e94000 Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Mon, 12 Jan 2026 14:50:32 -0800 Subject: [PATCH] migrate yolo/auto-edit keybindings (#16457) --- docs/cli/keyboard-shortcuts.md | 22 +++++++++---------- packages/cli/src/config/keyBindings.ts | 8 +++++++ .../src/ui/hooks/useAutoAcceptIndicator.ts | 5 +++-- packages/cli/src/ui/keyMatchers.test.ts | 12 ++++++++++ 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/docs/cli/keyboard-shortcuts.md b/docs/cli/keyboard-shortcuts.md index 22ce5866c0..56f19a45a0 100644 --- a/docs/cli/keyboard-shortcuts.md +++ b/docs/cli/keyboard-shortcuts.md @@ -91,15 +91,17 @@ available combinations. #### App Controls -| Action | Keys | -| ----------------------------------------------------------------- | ---------- | -| Toggle detailed error information. | `F12` | -| Toggle the full TODO list. | `Ctrl + T` | -| Toggle IDE context details. | `Ctrl + G` | -| Toggle Markdown rendering. | `Cmd + M` | -| Toggle copy mode when the terminal is using the alternate buffer. | `Ctrl + S` | -| Expand a height-constrained response to show additional lines. | `Ctrl + S` | -| Toggle focus between the shell and Gemini input. | `Ctrl + F` | +| Action | Keys | +| ----------------------------------------------------------------- | ------------- | +| Toggle detailed error information. | `F12` | +| Toggle the full TODO list. | `Ctrl + T` | +| Toggle IDE context details. | `Ctrl + G` | +| Toggle Markdown rendering. | `Cmd + M` | +| Toggle copy mode when the terminal is using the alternate buffer. | `Ctrl + S` | +| Toggle YOLO (auto-approval) mode for tool calls. | `Ctrl + Y` | +| Toggle Auto Edit (auto-accept edits) mode. | `Shift + Tab` | +| Expand a height-constrained response to show additional lines. | `Ctrl + S` | +| Toggle focus between the shell and Gemini input. | `Ctrl + F` | #### Session Control @@ -112,8 +114,6 @@ available combinations. ## Additional context-specific shortcuts -- `Ctrl+Y`: Toggle YOLO (auto-approval) mode for tool calls. -- `Shift+Tab`: Toggle Auto Edit (auto-accept edits) mode. - `Option+M` (macOS): Entering `ยต` with Option+M also toggles Markdown rendering, matching `Cmd+M`. - `!` on an empty prompt: Enter or exit shell mode. diff --git a/packages/cli/src/config/keyBindings.ts b/packages/cli/src/config/keyBindings.ts index b5a20b90e3..a919da1aff 100644 --- a/packages/cli/src/config/keyBindings.ts +++ b/packages/cli/src/config/keyBindings.ts @@ -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> = { [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]: diff --git a/packages/cli/src/ui/hooks/useAutoAcceptIndicator.ts b/packages/cli/src/ui/hooks/useAutoAcceptIndicator.ts index 6091420abd..282ac3ea7d 100644 --- a/packages/cli/src/ui/hooks/useAutoAcceptIndicator.ts +++ b/packages/cli/src/ui/hooks/useAutoAcceptIndicator.ts @@ -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 diff --git a/packages/cli/src/ui/keyMatchers.test.ts b/packages/cli/src/ui/keyMatchers.test.ts index 0982e84b2a..b3ed875e6e 100644 --- a/packages/cli/src/ui/keyMatchers.test.ts +++ b/packages/cli/src/ui/keyMatchers.test.ts @@ -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', () => {