File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -255,10 +255,21 @@ namespace winrt::Microsoft::Terminal::Control::implementation
255
255
}
256
256
else if (WI_IsFlagSet (buttonState, MouseButtonState::IsRightButtonDown))
257
257
{
258
- // Try to copy the text and clear the selection
259
- const auto successfulCopy = CopySelectionToClipboard (shiftEnabled, nullptr );
258
+ const auto copyOnSelect{ _core->CopyOnSelect () };
259
+ bool successfulCopy = false ;
260
+
261
+ // Don't try to copy if we're in copyOnSelect mode and have already
262
+ // copied this selection. GH#14464 demonstrates a scenario where the
263
+ // buffer contents might have changed since the selection was made,
264
+ // and copying here would cause weirdness.
265
+ if (_selectionNeedsToBeCopied || !copyOnSelect)
266
+ {
267
+ // Try to copy the text and clear the selection
268
+ successfulCopy = CopySelectionToClipboard (shiftEnabled, nullptr );
269
+ }
260
270
_core->ClearSelection ();
261
- if (_core->CopyOnSelect () || !successfulCopy)
271
+
272
+ if (copyOnSelect || !successfulCopy)
262
273
{
263
274
// CopyOnSelect: right click always pastes!
264
275
// Otherwise: no selection --> paste
Original file line number Diff line number Diff line change @@ -1041,6 +1041,9 @@ namespace ControlUnitTests
1041
1041
VERIFY_IS_TRUE (core->HasSelection ());
1042
1042
1043
1043
Log::Comment (L" --- Right-click to paste --- " );
1044
+ // Note from GH#14464: we don't want to copy _again_ at this point. The
1045
+ // copy occured when the selection was made, we shouldn't stealth-update
1046
+ // the clipboard again.
1044
1047
expectedCopyContents = std::nullopt;
1045
1048
expectedPaste = true ;
1046
1049
interactivity->PointerPressed (rightMouseDown,
@@ -1053,6 +1056,9 @@ namespace ControlUnitTests
1053
1056
1054
1057
void ControlInteractivityTests::CopyOnSelectAltBuffer ()
1055
1058
{
1059
+ // This test was inspired by GH#14464. Ultimately, it's similar to the
1060
+ // CopyOnSelectSimple, just with an alt buffer, and outputting text
1061
+ // after the selection was made.
1056
1062
auto [settings, conn] = _createSettingsAndConnection ();
1057
1063
settings->CopyOnSelect (true );
1058
1064
auto [core, interactivity] = _createCoreAndInteractivity (*settings, *conn);
You can’t perform that action at this time.
0 commit comments