From a7d49971d2cb89bb59ada097dfc926df0a8fca08 Mon Sep 17 00:00:00 2001 From: "A.K.M. Adib" Date: Mon, 4 May 2026 15:24:25 -0400 Subject: [PATCH] fix(cli): prompt for editor selection when CTRL-X is pressed and none is configured --- packages/cli/src/ui/components/shared/text-buffer.ts | 10 +++++++++- packages/cli/src/ui/utils/editorUtils.ts | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/ui/components/shared/text-buffer.ts b/packages/cli/src/ui/components/shared/text-buffer.ts index 89b6f8f158..b72c1bea45 100644 --- a/packages/cli/src/ui/components/shared/text-buffer.ts +++ b/packages/cli/src/ui/components/shared/text-buffer.ts @@ -12,6 +12,7 @@ import { useState, useCallback, useEffect, useMemo, useReducer } from 'react'; import { LRUCache } from 'mnemonist'; import { coreEvents, + CoreEvent, debugLogger, unescapePath, type EditorType, @@ -29,7 +30,10 @@ import { Command } from '../../key/keyMatchers.js'; import type { VimAction } from './vim-buffer-actions.js'; import { handleVimAction } from './vim-buffer-actions.js'; import { LRU_BUFFER_PERF_CACHE_LIMIT } from '../../constants.js'; -import { openFileInEditor } from '../../utils/editorUtils.js'; +import { + openFileInEditor, + EditorNotConfiguredError, +} from '../../utils/editorUtils.js'; import { useKeyMatchers } from '../../hooks/useKeyMatchers.js'; export const LARGE_PASTE_LINE_THRESHOLD = 5; @@ -3342,6 +3346,10 @@ export function useTextBuffer({ dispatch({ type: 'set_text', payload: newText, pushToUndo: false }); } catch (err) { + if (err instanceof EditorNotConfiguredError) { + coreEvents.emit(CoreEvent.RequestEditorSelection); + return; + } coreEvents.emitFeedback( 'error', '[useTextBuffer] external editor error', diff --git a/packages/cli/src/ui/utils/editorUtils.ts b/packages/cli/src/ui/utils/editorUtils.ts index 7b9efd5a81..354828dc0c 100644 --- a/packages/cli/src/ui/utils/editorUtils.ts +++ b/packages/cli/src/ui/utils/editorUtils.ts @@ -15,6 +15,13 @@ import { isTerminalEditor, } from '@google/gemini-cli-core'; +export class EditorNotConfiguredError extends Error { + constructor() { + super('No external editor configured'); + this.name = 'EditorNotConfiguredError'; + } +} + /** * Opens a file in an external editor and waits for it to close. * Handles raw mode switching to ensure the editor can interact with the terminal. @@ -58,7 +65,7 @@ export async function openFileInEditor( } if (!command) { - command = process.platform === 'win32' ? 'notepad' : 'vi'; + throw new EditorNotConfiguredError(); } const [executable = '', ...initialArgs] = command.split(' ');