Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/hooks/useAIViewKeybinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down