From 756fd444b1d443320cf2ed6887d4b65aa67a9a03 Mon Sep 17 00:00:00 2001 From: Love F Date: Thu, 28 Oct 2021 17:38:23 +0200 Subject: [PATCH] Trim trailing whitespace option (#11473) ## Summary of the Pull Request Opt in setting to trim trailing white space when pasting a text into the terminal ## References ## PR Checklist * [x] Closes #9400 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx * [ ] Schema updated. * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed Manually testing to paste text with and without trailing white spaces, with and without the option activated --- .../SerializationTests.cpp | 1 + src/cascadia/TerminalApp/TerminalPage.cpp | 16 ++++++++++++++++ .../TerminalSettingsEditor/Interaction.xaml | 5 +++++ .../Resources/en-US/Resources.resw | 6 +++++- .../TerminalSettingsModel/GlobalAppSettings.cpp | 4 ++++ .../TerminalSettingsModel/GlobalAppSettings.h | 1 + .../TerminalSettingsModel/GlobalAppSettings.idl | 1 + src/cascadia/TerminalSettingsModel/defaults.json | 1 + 8 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp b/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp index 10214b861..ff2aefdb6 100644 --- a/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp +++ b/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp @@ -97,6 +97,7 @@ namespace SettingsModelLocalTests "confirmCloseAllTabs": true, "largePasteWarning": true, "multiLinePasteWarning": true, + "trimPaste": true, "experimental.input.forceVT": false, "experimental.rendering.forceFullRepaint": false, diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index b779b5069..7a2a7162f 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1869,6 +1869,22 @@ namespace winrt::TerminalApp::implementation } } + if (_settings.GlobalSettings().TrimPaste()) + { + std::wstring_view textView{ text }; + const auto pos = textView.find_last_not_of(L"\t\n\v\f\r "); + if (pos == textView.npos) + { + // Text is all white space, nothing to paste + co_return; + } + else if (const auto toRemove = textView.size() - 1 - pos; toRemove > 0) + { + textView.remove_suffix(toRemove); + text = { textView }; + } + } + bool warnMultiLine = _settings.GlobalSettings().WarnAboutMultiLinePaste(); if (warnMultiLine) { diff --git a/src/cascadia/TerminalSettingsEditor/Interaction.xaml b/src/cascadia/TerminalSettingsEditor/Interaction.xaml index 6b93c5847..8bdf829f6 100644 --- a/src/cascadia/TerminalSettingsEditor/Interaction.xaml +++ b/src/cascadia/TerminalSettingsEditor/Interaction.xaml @@ -45,6 +45,11 @@ + + + + + +