Skip to content

fix: prevent clipboard overwrite on single click without selection#124

Open
zerone0x wants to merge 1 commit intocoder:mainfrom
zerone0x:fix/clipboard-on-single-click
Open

fix: prevent clipboard overwrite on single click without selection#124
zerone0x wants to merge 1 commit intocoder:mainfrom
zerone0x:fix/clipboard-on-single-click

Conversation

@zerone0x
Copy link

Summary

Fixes #108

Single clicks on terminal cells were triggering copyToClipboard() in the mouseup handler without checking hasSelection() first. This caused the user's clipboard to be silently overwritten with a single character from the clicked cell, even when no text was selected.

Changes

  • Added hasSelection() guard in the mouseup handler in SelectionManager, matching the existing pattern in the public copySelection() API

Root Cause

The mousedown handler sets both selectionStart and selectionEnd to the same cell on click, and isSelecting = true. When mouseup fires (without any drag), getSelection() returns the character at that single cell, and copyToClipboard() overwrites the clipboard. The hasSelection() method correctly identifies same-cell selections as not real selections, but the mouseup handler wasn't calling it.

Test Plan

  • Click on a terminal cell without dragging → clipboard should NOT be modified
  • Click and drag to select text → clipboard should contain selected text
  • Double-click to select a word → clipboard should contain the word
  • Cmd+C with selection → should still copy correctly

🤖 Generated with Claude Code (issue-hunter-pro)

The mouseup handler in SelectionManager was calling copyToClipboard()
without first checking hasSelection(), causing single clicks on terminal
cells to copy the character at that position to the clipboard. This
overwrote the user's clipboard contents unexpectedly.

Added a hasSelection() guard in the mouseup handler to match the pattern
already used in the public copySelection() API.

Fixes coder#108

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

copyToClipboard fires on single click without selection

1 participant