Fix copyOnSelect right-click overwriting clipboard with stale selection#19943
Fix copyOnSelect right-click overwriting clipboard with stale selection#19943sagarbhure-msft wants to merge 1 commit intomicrosoft:mainfrom
Conversation
|
@microsoft-github-policy-service agree |
| // no selection --> paste | ||
| RequestPasteTextFromClipboard(); | ||
| } | ||
| } |
There was a problem hiding this comment.
This can be shortened IMO:
// GH#19942: With copyOnSelect the selection was already copied when the
// user released the left mouse button. Don't re-copy it on right-click.
// Otherwise, we copy the selection if any.
const auto paste = _core->CopyOnSelect() || !CopySelectionToClipboard(shiftEnabled, false, _core->Settings().CopyFormatting());
_core->ClearSelection();
// With copyOnSelect any right click turns into a paste.
// Otherwise, only if there was no selection to copy, it's a paste.
if (paste)
{
RequestPasteTextFromClipboard();
}|
Reviewers may want to x-ref this much much older PR of mine: |
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... |
Summary of the Pull Request
Fix
copyOnSelectright-click paste overwriting the clipboard with a stale selection instead of pasting the current clipboard contents.References and Relevant Issues
Closes #19942
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