diff --git a/src/hooks/useAIViewKeybinds.ts b/src/hooks/useAIViewKeybinds.ts index 982137c85..1086af3a0 100644 --- a/src/hooks/useAIViewKeybinds.ts +++ b/src/hooks/useAIViewKeybinds.ts @@ -67,15 +67,32 @@ export function useAIViewKeybinds({ } // Normal stream interrupt (non-compaction) - // Don't intercept if user is typing in an input field - if (!isEditableElement(e.target) && (canInterrupt || showRetryBarrier)) { + // Allow interrupt in editable elements if there's no text selection + // This way Ctrl+C works for both copy (when text is selected) and interrupt (when not) + const inEditableElement = isEditableElement(e.target); + let hasSelection = false; + + if (inEditableElement) { + // For input/textarea elements, check selectionStart/selectionEnd + // (window.getSelection() doesn't work for form elements) + const target = e.target as HTMLInputElement | HTMLTextAreaElement; + hasSelection = + typeof target.selectionStart === "number" && + typeof target.selectionEnd === "number" && + target.selectionStart !== target.selectionEnd; + } else { + // For contentEditable and other elements, use window.getSelection() + hasSelection = (window.getSelection()?.toString().length ?? 0) > 0; + } + + if ((canInterrupt || showRetryBarrier) && (!inEditableElement || !hasSelection)) { e.preventDefault(); setAutoRetry(false); // User explicitly stopped - don't auto-retry void window.api.workspace.interruptStream(workspaceId); return; } - // Let browser handle Ctrl+C (copy) in editable elements + // Let browser handle Ctrl+C (copy) when there's a selection return; }