mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-01 01:56:46 +00:00
prevent auto-execute on paste and preserve multi-line content in chat input (#5834)
Co-authored-by: HYPERXD <Alish-0x@users.noreply.github.com> Co-authored-by: Allen Hutchison <adh@google.com>
This commit is contained in:
@@ -71,6 +71,8 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
const [escPressCount, setEscPressCount] = useState(0);
|
||||
const [showEscapePrompt, setShowEscapePrompt] = useState(false);
|
||||
const escapeTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const [recentPasteTime, setRecentPasteTime] = useState<number | null>(null);
|
||||
const pasteTimeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
const [dirs, setDirs] = useState<readonly string[]>(
|
||||
config.getWorkspaceContext().getDirectories(),
|
||||
@@ -130,6 +132,9 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
if (escapeTimerRef.current) {
|
||||
clearTimeout(escapeTimerRef.current);
|
||||
}
|
||||
if (pasteTimeoutRef.current) {
|
||||
clearTimeout(pasteTimeoutRef.current);
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
@@ -245,6 +250,20 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
}
|
||||
|
||||
if (key.paste) {
|
||||
// Record paste time to prevent accidental auto-submission
|
||||
setRecentPasteTime(Date.now());
|
||||
|
||||
// Clear any existing paste timeout
|
||||
if (pasteTimeoutRef.current) {
|
||||
clearTimeout(pasteTimeoutRef.current);
|
||||
}
|
||||
|
||||
// Clear the paste protection after a safe delay
|
||||
pasteTimeoutRef.current = setTimeout(() => {
|
||||
setRecentPasteTime(null);
|
||||
pasteTimeoutRef.current = null;
|
||||
}, 500);
|
||||
|
||||
// Ensure we never accidentally interpret paste as regular input.
|
||||
buffer.handleInput(key);
|
||||
return;
|
||||
@@ -460,6 +479,12 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
|
||||
if (keyMatchers[Command.SUBMIT](key)) {
|
||||
if (buffer.text.trim()) {
|
||||
// Check if a paste operation occurred recently to prevent accidental auto-submission
|
||||
if (recentPasteTime !== null) {
|
||||
// Paste occurred recently, ignore this submit to prevent auto-execution
|
||||
return;
|
||||
}
|
||||
|
||||
const [row, col] = buffer.cursor;
|
||||
const line = buffer.lines[row];
|
||||
const charBefore = col > 0 ? cpSlice(line, col - 1, col) : '';
|
||||
@@ -558,6 +583,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
reverseSearchActive,
|
||||
textBeforeReverseSearch,
|
||||
cursorPosition,
|
||||
recentPasteTime,
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user