diff --git a/packages/cli/src/ui/AppContainer.tsx b/packages/cli/src/ui/AppContainer.tsx index fbf6301857..0e1b936b76 100644 --- a/packages/cli/src/ui/AppContainer.tsx +++ b/packages/cli/src/ui/AppContainer.tsx @@ -898,7 +898,7 @@ Logging in with Google... Please restart Gemini CLI to continue. >(); const [showEscapePrompt, setShowEscapePrompt] = useState(false); const [showIdeRestartPrompt, setShowIdeRestartPrompt] = useState(false); - const [selectionWarning, setSelectionWarning] = useState(false); + const [warningMessage, setWarningMessage] = useState(null); const { isFolderTrustDialogOpen, handleFolderTrustSelect, isRestarting } = useFolderTrust(settings, setIsTrustedFolder, historyManager.addItem); @@ -910,18 +910,28 @@ Logging in with Google... Please restart Gemini CLI to continue. useEffect(() => { let timeoutId: NodeJS.Timeout; - const handleSelectionWarning = () => { - setSelectionWarning(true); + + const handleWarning = (message: string) => { + setWarningMessage(message); if (timeoutId) { clearTimeout(timeoutId); } timeoutId = setTimeout(() => { - setSelectionWarning(false); + setWarningMessage(null); }, WARNING_PROMPT_DURATION_MS); }; + + const handleSelectionWarning = () => { + handleWarning('Press Ctrl-S to enter selection mode to copy text.'); + }; + const handlePasteTimeout = () => { + handleWarning('Paste Timed out. Possibly due to slow connection.'); + }; appEvents.on(AppEvent.SelectionWarning, handleSelectionWarning); + appEvents.on(AppEvent.PasteTimeout, handlePasteTimeout); return () => { appEvents.off(AppEvent.SelectionWarning, handleSelectionWarning); + appEvents.off(AppEvent.PasteTimeout, handlePasteTimeout); if (timeoutId) { clearTimeout(timeoutId); } @@ -1373,7 +1383,7 @@ Logging in with Google... Please restart Gemini CLI to continue. embeddedShellFocused, showDebugProfiler, copyModeEnabled, - selectionWarning, + warningMessage, }), [ isThemeDialogOpen, @@ -1460,7 +1470,7 @@ Logging in with Google... Please restart Gemini CLI to continue. apiKeyDefaultValue, authState, copyModeEnabled, - selectionWarning, + warningMessage, ], ); diff --git a/packages/cli/src/ui/components/Composer.tsx b/packages/cli/src/ui/components/Composer.tsx index 6654541816..15558082a6 100644 --- a/packages/cli/src/ui/components/Composer.tsx +++ b/packages/cli/src/ui/components/Composer.tsx @@ -99,10 +99,8 @@ export const Composer = () => { Press Ctrl+C again to exit. - ) : uiState.selectionWarning ? ( - - Press Ctrl-S to enter selection mode to copy text. - + ) : uiState.warningMessage ? ( + {uiState.warningMessage} ) : uiState.ctrlDPressedOnce ? ( Press Ctrl+D again to exit. diff --git a/packages/cli/src/ui/contexts/KeypressContext.tsx b/packages/cli/src/ui/contexts/KeypressContext.tsx index 5354d66d38..8be139a38f 100644 --- a/packages/cli/src/ui/contexts/KeypressContext.tsx +++ b/packages/cli/src/ui/contexts/KeypressContext.tsx @@ -18,10 +18,11 @@ import { import { ESC } from '../utils/input.js'; import { parseMouseEvent } from '../utils/mouse.js'; import { FOCUS_IN, FOCUS_OUT } from '../hooks/useFocus.js'; +import { appEvents, AppEvent } from '../../utils/events.js'; export const BACKSLASH_ENTER_TIMEOUT = 5; export const ESC_TIMEOUT = 50; -export const PASTE_TIMEOUT = 50; +export const PASTE_TIMEOUT = 30_000; // Parse the key itself const KEY_INFO_MAP: Record< @@ -211,7 +212,12 @@ function bufferPaste( key = yield; clearTimeout(timeoutId); - if (key === null || key.name === 'paste-end') { + if (key === null) { + appEvents.emit(AppEvent.PasteTimeout); + break; + } + + if (key.name === 'paste-end') { break; } buffer += key.sequence; diff --git a/packages/cli/src/ui/contexts/UIStateContext.tsx b/packages/cli/src/ui/contexts/UIStateContext.tsx index c96000ee98..d46e58b567 100644 --- a/packages/cli/src/ui/contexts/UIStateContext.tsx +++ b/packages/cli/src/ui/contexts/UIStateContext.tsx @@ -125,7 +125,7 @@ export interface UIState { showDebugProfiler: boolean; showFullTodos: boolean; copyModeEnabled: boolean; - selectionWarning: boolean; + warningMessage: string | null; } export const UIStateContext = createContext(null); diff --git a/packages/cli/src/utils/events.ts b/packages/cli/src/utils/events.ts index 50415d150f..514c0039e0 100644 --- a/packages/cli/src/utils/events.ts +++ b/packages/cli/src/utils/events.ts @@ -14,6 +14,7 @@ export enum AppEvent { Flicker = 'flicker', McpClientUpdate = 'mcp-client-update', SelectionWarning = 'selection-warning', + PasteTimeout = 'paste-timeout', } export interface AppEvents extends ExtensionEvents { @@ -23,6 +24,7 @@ export interface AppEvents extends ExtensionEvents { [AppEvent.Flicker]: never[]; [AppEvent.McpClientUpdate]: Array | never>; [AppEvent.SelectionWarning]: never[]; + [AppEvent.PasteTimeout]: never[]; } export const appEvents = new EventEmitter();