Skip to content

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

Merged
deansheather merged 1 commit intocoder:mainfrom
zerone0x:fix/clipboard-on-single-click
Feb 19, 2026
Merged

fix: prevent clipboard overwrite on single click without selection#124
deansheather merged 1 commit intocoder:mainfrom
zerone0x:fix/clipboard-on-single-click

Conversation

@zerone0x
Copy link
Contributor

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>
@coder coder deleted a comment from chatgpt-codex-connector bot Feb 19, 2026
@ibetitsmike
Copy link

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@deansheather deansheather merged commit fd09412 into coder:main Feb 19, 2026
5 checks passed
@deansheather
Copy link
Member

Thanks for the contribution!

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

3 participants

Comments