Repository navigation
Fix copyOnSelect right-click overwriting clipboard with stale selection - #19943
Conversation
|
@microsoft-github-policy-service agree |
|
Reviewers may want to x-ref this much much older PR of mine: |
Carlos Zamora (carlos-zamora)
left a comment
There was a problem hiding this comment.
Thanks for the x-ref Mike!
Yeah, the same problem from #14635 happens. Blocking over that.
Bug:
- ensure copy on select is enabled
- enter mark mode
- make a selection with mark mode
- right-click to copy/paste
expected: selection is copied and pasted immediately
NOTE: similar thing happens when you make a mouse selection, then modify it using quick-edit keys (i.e. shift+right). The selected text is not copied and pasted immediately.
from #14635 (review)
|
Root cause from a chat with GH Copilot:
|
ack, looking into this... |
Fixes the mark-mode and quick-edit (shift+arrow) bug identified in PR microsoft#14635's review: _selectionNeedsToBeCopied was only set in SetEndSelectionPoint() (mouse drag), so keyboard-driven selections were incorrectly treated as already-copied on right-click. Fix: subscribe to ControlCore::UpdateSelectionMarkers in the ControlInteractivity constructor so the flag is set for ALL selection types (mouse, mark mode, quick-edit, select-all). The right-click handler now uses the same gating logic from PR microsoft#14635 (_selectionNeedsToBeCopied || !copyOnSelect) to decide whether to copy, and always pastes in copyOnSelect mode. Also collapses the if/else into a compact conditional per lhecker's review suggestion. Closes microsoft#14464 Fixes microsoft#19942
|
Pushed a follow-up commit addressing all review feedback:
|
ad7b34e
into
microsoft:main
…on (#19943) ## Summary of the Pull Request Fix `copyOnSelect` right-click paste overwriting the clipboard with a stale selection instead of pasting the current clipboard contents. ## Detailed Description of the Pull Request / Additional comments When `copyOnSelect` is enabled, the selected text is already copied to the clipboard on left mouse button release in `PointerReleased`. The selection is intentionally left visible as a visual reference (the `_selectionNeedsToBeCopied` flag is set to `false` to track that the copy already happened). However, the right-click handler in `PointerPressed` unconditionally called `CopySelectionToClipboard()` before pasting, ignoring both the `copyOnSelect` setting and the `_selectionNeedsToBeCopied` flag. This caused any still-visible selection to be re-copied to the clipboard, overwriting whatever the user may have copied from another application (or another terminal tab) in the meantime. This change splits the right-click behavior based on the `copyOnSelect` setting: - **`copyOnSelect: true`** — Skip the redundant copy, clear the selection, and paste directly. The text was already copied on mouse-up. - **`copyOnSelect: false`** — Preserve existing behavior: copy the selection (if any), clear it, and paste only if there was no selection to copy. ## Validation Steps Performed 1. Set `"copyOnSelect": true` in `settings.json`. 2. Selected text in a terminal pane - verified it was copied to clipboard on mouse-up. 3. Switched to Notepad, copied different text ("NEW TEXT"). 4. Switched back to Terminal (selection still visible), right-clicked — verified "NEW TEXT" was pasted, not the old selection. 5. Verified right-click with no active selection still pastes clipboard contents. 6. Verified right-click immediately after selecting (no app switch) pastes the just-selected text. 7. Set `"copyOnSelect": false` — verified right-click still copies selection first, then pastes only when no selection exists (original behavior unchanged). 8. Verified tab-switching with an active selection does not cause stale clipboard overwrites on right-click. ## PR Checklist Closes #14465 (dupe of #19942) --------- Co-authored-by: Sagar Bhure <sagarbhure@microsoft.com> (cherry picked from commit ad7b34e) Service-Card-Id: PVTI_lADOAF3p4s4BBcTlzgn30Lw Service-Version: 1.24
…on (#19943) ## Summary of the Pull Request Fix `copyOnSelect` right-click paste overwriting the clipboard with a stale selection instead of pasting the current clipboard contents. ## Detailed Description of the Pull Request / Additional comments When `copyOnSelect` is enabled, the selected text is already copied to the clipboard on left mouse button release in `PointerReleased`. The selection is intentionally left visible as a visual reference (the `_selectionNeedsToBeCopied` flag is set to `false` to track that the copy already happened). However, the right-click handler in `PointerPressed` unconditionally called `CopySelectionToClipboard()` before pasting, ignoring both the `copyOnSelect` setting and the `_selectionNeedsToBeCopied` flag. This caused any still-visible selection to be re-copied to the clipboard, overwriting whatever the user may have copied from another application (or another terminal tab) in the meantime. This change splits the right-click behavior based on the `copyOnSelect` setting: - **`copyOnSelect: true`** — Skip the redundant copy, clear the selection, and paste directly. The text was already copied on mouse-up. - **`copyOnSelect: false`** — Preserve existing behavior: copy the selection (if any), clear it, and paste only if there was no selection to copy. ## Validation Steps Performed 1. Set `"copyOnSelect": true` in `settings.json`. 2. Selected text in a terminal pane - verified it was copied to clipboard on mouse-up. 3. Switched to Notepad, copied different text ("NEW TEXT"). 4. Switched back to Terminal (selection still visible), right-clicked — verified "NEW TEXT" was pasted, not the old selection. 5. Verified right-click with no active selection still pastes clipboard contents. 6. Verified right-click immediately after selecting (no app switch) pastes the just-selected text. 7. Set `"copyOnSelect": false` — verified right-click still copies selection first, then pastes only when no selection exists (original behavior unchanged). 8. Verified tab-switching with an active selection does not cause stale clipboard overwrites on right-click. ## PR Checklist Closes #14465 (dupe of #19942) --------- Co-authored-by: Sagar Bhure <sagarbhure@microsoft.com> (cherry picked from commit ad7b34e) Service-Card-Id: PVTI_lADOAF3p4s4BQX0-zgn30Ls Service-Version: 1.25

Summary of the Pull Request
Fix
copyOnSelectright-click paste overwriting the clipboard with a stale selection instead of pasting the current clipboard contents.Detailed Description of the Pull Request / Additional comments
When
copyOnSelectis enabled, the selected text is already copied to the clipboard on left mouse button release inPointerReleased. The selection is intentionally left visible as a visual reference (the_selectionNeedsToBeCopiedflag is set tofalseto track that the copy already happened).However, the right-click handler in
PointerPressedunconditionally calledCopySelectionToClipboard()before pasting, ignoring both thecopyOnSelectsetting and the_selectionNeedsToBeCopiedflag. This caused any still-visible selection to be re-copied to the clipboard, overwriting whatever the user may have copied from another application (or another terminal tab) in the meantime.This change splits the right-click behavior based on the
copyOnSelectsetting:copyOnSelect: true— Skip the redundant copy, clear the selection, and paste directly. The text was already copied on mouse-up.copyOnSelect: false— Preserve existing behavior: copy the selection (if any), clear it, and paste only if there was no selection to copy.Validation Steps Performed
"copyOnSelect": trueinsettings.json."copyOnSelect": false— verified right-click still copies selection first, then pastes only when no selection exists (original behavior unchanged).PR Checklist
Closes #14464 (dupe of #19942)