Repository navigation
[1.14] Fix keyboard selection and copyOnSelect interaction #13360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -142,13 +142,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
| // Method Description: | ||
| // - Given a copy-able selection, get the selected text from the buffer and send it to the | ||
| // Windows Clipboard (CascadiaWin32:main.cpp). | ||
| // - CopyOnSelect does NOT clear the selection | ||
| // Arguments: | ||
| // - singleLine: collapse all of the text to one line | ||
| // - formats: which formats to copy (defined by action's CopyFormatting arg). nullptr | ||
| // if we should defer which formats are copied to the global setting | ||
| // - clearSelection: if true, clear the selection after copying it. Used for CopyOnSelect. | ||
| bool ControlInteractivity::CopySelectionToClipboard(bool singleLine, | ||
| const Windows::Foundation::IReference<CopyFormat>& formats) | ||
| const Windows::Foundation::IReference<CopyFormat>& formats, | ||
| bool clearSelection) | ||
| { | ||
| if (_core) | ||
| { | ||
|
|
@@ -164,7 +165,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
| // Mark the current selection as copied | ||
| _selectionNeedsToBeCopied = false; | ||
|
|
||
| return _core->CopySelectionToClipboard(singleLine, formats); | ||
| return _core->CopySelectionToClipboard(singleLine, formats, clearSelection); | ||
| } | ||
|
|
||
| return false; | ||
|
|
@@ -257,15 +258,27 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
| } | ||
| else if (WI_IsFlagSet(buttonState, MouseButtonState::IsRightButtonDown)) | ||
| { | ||
| // CopyOnSelect right click always pastes | ||
| if (_core->CopyOnSelect() || !_core->HasSelection()) | ||
| if (_core->CopyOnSelect()) | ||
| { | ||
| // CopyOnSelect: | ||
| // 1. keyboard selection? --> copy the new content first | ||
| // 2. right click always pastes! | ||
| if (_core->IsInQuickEditMode()) | ||
| { | ||
| CopySelectionToClipboard(shiftEnabled, nullptr); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're When is
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes and no. No, because "quick edit mode" is specifically when you add these steps to the scenario above... (3) shift+right to extend the selection a bit. Then, when you right-click, we already copied the wrong contents! We copied the data when you let go, not when you're right-clicking. So this extra code just detects when you've done step 3 and we need to copy the contents again.
They're mutually exclusive. After a quick chat with Dustin, here's a new approach... We just have 3 modes in increasing order. All mutually exclusive, but all useful to know when to show the selection markers and what trickery could occur. That also lets me combine
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this approach only applies to 1.15+ |
||
| } | ||
| RequestPasteTextFromClipboard(); | ||
| } | ||
| else | ||
| else if (_core->HasSelection()) | ||
| { | ||
| // copy selected text | ||
| CopySelectionToClipboard(shiftEnabled, nullptr); | ||
| } | ||
| else | ||
| { | ||
| // no selection --> paste | ||
| RequestPasteTextFromClipboard(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -383,7 +396,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
| isLeftMouseRelease && | ||
| _selectionNeedsToBeCopied) | ||
| { | ||
| CopySelectionToClipboard(false, nullptr); | ||
| // IMPORTANT! | ||
| // Set clearSelection to false here! | ||
| // Otherwise, the selection will be cleared immediately after you make it. | ||
| CopySelectionToClipboard(false, nullptr, /*clearSelection*/ false); | ||
| } | ||
|
|
||
| _singleClickTouchdownPos = std::nullopt; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.