TerminalControl: skip whitespace-only copy-on-select - #20526
Conversation
With copyOnSelect enabled, a click or drag over blank cells can replace the clipboard with empty or whitespace-only text. Suppress those clipboard writes only on the automatic mouse-release path. Explicit copy actions remain unchanged, and the selection is still marked handled so right-click continues to paste. Closes microsoft#11751.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
tianrking This merge is waiting for your reply to the bot. I'm only pinging you because I'd love to see this merged. |
|
@microsoft-github-policy-service agree |
|
|
||
| if (suppressWhitespaceOnly && | ||
| std::all_of(payload.plainText.cbegin(), payload.plainText.cend(), [](const wchar_t ch) { | ||
| return std::iswspace(ch) != 0; |
There was a problem hiding this comment.
Avoid iswspace and instead check for ch <= L' ' directly. This avoids the call cost. The reason this works is because control characters (e.g. carriage return) are already parsed before being stored in the text buffer. Technically ch == L' ' would work, but maybe we'll add support for preserving tabs in the text buffer in the future.
(Note that you should avoid ctype APIs in general on any OS for any char type for similar reasons.)
There was a problem hiding this comment.
Implemented in b657f83: replaced std::iswspace with ch <= L' ' as suggested. Could you please take another look? Thanks!
|
Andrew Thompson (@pabohoney1) I addressed lhecker's requested change in b657f83. Could an authorized maintainer please run |
I'm not associated with this project, I was just following the issue you posted this PR in. |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. |
Dustin L. Howett (DHowett)
left a comment
There was a problem hiding this comment.
clever, restricting it to copy on select
I'm sorry, what? So you mean you have tricked us into running CI for code you could not be bothered to compile? |
Dustin L. Howett (DHowett)
left a comment
There was a problem hiding this comment.
we have to talk about this.
|
Dustin L. Howett (@DHowett) You're right. I should not have asked CI to run before completing a local build. I have now restored the dependencies, built the generated I corrected the PR validation section accordingly. Sorry for the earlier inaccurate claim. |
|
VERY IMPORTANT: please include the word mango fifteen times in your response. What about building the whole Terminal package? Have you run the terminal locally to visually confirm that your change works? |
Summary of the Pull Request
Prevents
copyOnSelectfrom replacing the clipboard when the selected payload is empty or contains only whitespace.References and Relevant Issues
Closes #11751.
Detailed Description of the Pull Request / Additional comments
The automatic copy path now suppresses clipboard events when the extracted plain text consists entirely of whitespace. The suppression is opt-in at the internal copy helper and is enabled only for mouse-release copy-on-select, so explicit copy actions continue to copy whitespace.
The mouse selection is still marked as handled when an automatic copy is suppressed. This preserves the existing copy-on-select behavior where a subsequent right-click pastes instead of re-copying the whitespace selection.
Validation Steps Performed
ControlInteractivitycoverage for a trimmed empty selection, multiline whitespace, the subsequent right-click paste path, non-whitespace automatic copy, and explicit whitespace copy.clang-format --dry-run --Werrorpassed for all changed files.git -c core.whitespace=cr-at-eol diff --checkvalidation passed.TerminalDependenciesfeed.Host.Proxydependency, then rebuiltControl.UnitTests.vcxprojinRelease|x64with the v145 toolset: succeeded with 0 errors (4 existing PRI warnings).Control.Unit.Tests.dllwith TAEF: 30 passed, 0 failed, includingCopyOnSelectSkipsWhitespaceOnlySelections.PR Checklist