fix: Ctrl+C should copy selected text rather than interrupt Claude #195

Closed
opened 2026-03-06 12:00:15 -08:00 by hikari · 0 comments
Owner

Problem

Pressing Ctrl+C whilst text is selected in the terminal sends an interrupt signal to Claude Code instead of copying the selected text. This is surprising behaviour — users naturally expect Ctrl+C to copy when there's a selection.

Expected Behaviour

  • Text selectedCtrl+C copies to clipboard (standard OS behaviour)
  • No text selectedCtrl+C interrupts the running Claude process (existing behaviour)

Implementation Notes

In the Ctrl+C keydown handler, check window.getSelection() before deciding what to do:

if (e.ctrlKey && e.key === "c") {
  const selection = window.getSelection();
  if (selection && selection.toString().length > 0) {
    // Let the browser handle copy natively — do not interrupt
    return;
  }
  // No selection — send interrupt as usual
  handleInterrupt();
}

The key is to not call e.preventDefault() when a selection exists, allowing the browser's native copy behaviour to proceed.

Acceptance Criteria

  • Ctrl+C with selected text copies to clipboard and does not interrupt Claude
  • Ctrl+C with no selection still interrupts Claude as expected
  • Behaviour is consistent whether Claude is running or idle
  • Tests updated to cover both branches of the selection check

This issue was created with help from Hikari~ 🌸

## Problem Pressing `Ctrl+C` whilst text is selected in the terminal sends an interrupt signal to Claude Code instead of copying the selected text. This is surprising behaviour — users naturally expect `Ctrl+C` to copy when there's a selection. ## Expected Behaviour - **Text selected** → `Ctrl+C` copies to clipboard (standard OS behaviour) - **No text selected** → `Ctrl+C` interrupts the running Claude process (existing behaviour) ## Implementation Notes In the `Ctrl+C` keydown handler, check `window.getSelection()` before deciding what to do: ```typescript if (e.ctrlKey && e.key === "c") { const selection = window.getSelection(); if (selection && selection.toString().length > 0) { // Let the browser handle copy natively — do not interrupt return; } // No selection — send interrupt as usual handleInterrupt(); } ``` The key is to **not call `e.preventDefault()`** when a selection exists, allowing the browser's native copy behaviour to proceed. ## Acceptance Criteria - [ ] `Ctrl+C` with selected text copies to clipboard and does not interrupt Claude - [ ] `Ctrl+C` with no selection still interrupts Claude as expected - [ ] Behaviour is consistent whether Claude is running or idle - [ ] Tests updated to cover both branches of the selection check ✨ This issue was created with help from Hikari~ 🌸
naomi closed this issue 2026-03-07 03:08:34 -08:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: nhcarrigan/hikari-desktop#195