Trim trailing whitespace option (#11473)
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request Opt in setting to trim trailing white space when pasting a text into the terminal <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References <!-- Please review the items on the PR checklist before submitting--> ## 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 <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed Manually testing to paste text with and without trailing white spaces, with and without the option activated
This commit is contained in:
parent
5bc094e12a
commit
756fd444b1
|
@ -97,6 +97,7 @@ namespace SettingsModelLocalTests
|
|||
"confirmCloseAllTabs": true,
|
||||
"largePasteWarning": true,
|
||||
"multiLinePasteWarning": true,
|
||||
"trimPaste": true,
|
||||
|
||||
"experimental.input.forceVT": false,
|
||||
"experimental.rendering.forceFullRepaint": false,
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -45,6 +45,11 @@
|
|||
<ToggleSwitch IsOn="{x:Bind State.Globals.TrimBlockSelection, Mode=TwoWay}" />
|
||||
</local:SettingContainer>
|
||||
|
||||
<!-- Trim Paste -->
|
||||
<local:SettingContainer x:Uid="Globals_TrimPaste">
|
||||
<ToggleSwitch IsOn="{x:Bind State.Globals.TrimPaste, Mode=TwoWay}" />
|
||||
</local:SettingContainer>
|
||||
|
||||
<!-- Word Delimiters -->
|
||||
<local:SettingContainer x:Uid="Globals_WordDelimiters">
|
||||
<TextBox IsSpellCheckEnabled="False"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
@ -247,6 +247,10 @@
|
|||
<value>Remove trailing white-space in rectangular selection</value>
|
||||
<comment>Header for a control to toggle whether a text selected with block selection should be trimmed of white spaces when copied to the clipboard, or not.</comment>
|
||||
</data>
|
||||
<data name="Globals_TrimPaste.Header" xml:space="preserve">
|
||||
<value>Remove trailing white-space when pasting</value>
|
||||
<comment>Header for a control to toggle whether pasted text should be trimmed of white spaces, or not.</comment>
|
||||
</data>
|
||||
<data name="Globals_KeybindingsDisclaimer.Text" xml:space="preserve">
|
||||
<value>Below are the currently bound keys, which can be modified by editing the JSON settings file.</value>
|
||||
<comment>A disclaimer located at the top of the actions page that presents the list of keybindings.</comment>
|
||||
|
|
|
@ -35,6 +35,7 @@ static constexpr std::string_view CopyOnSelectKey{ "copyOnSelect" };
|
|||
static constexpr std::string_view CopyFormattingKey{ "copyFormatting" };
|
||||
static constexpr std::string_view WarnAboutLargePasteKey{ "largePasteWarning" };
|
||||
static constexpr std::string_view WarnAboutMultiLinePasteKey{ "multiLinePasteWarning" };
|
||||
static constexpr std::string_view TrimPasteKey{ "trimPaste" };
|
||||
static constexpr std::string_view LaunchModeKey{ "launchMode" };
|
||||
static constexpr std::string_view ConfirmCloseAllKey{ "confirmCloseAllTabs" };
|
||||
static constexpr std::string_view SnapToGridOnResizeKey{ "snapToGridOnResize" };
|
||||
|
@ -101,6 +102,7 @@ winrt::com_ptr<GlobalAppSettings> GlobalAppSettings::Copy() const
|
|||
globals->_CopyFormatting = _CopyFormatting;
|
||||
globals->_WarnAboutLargePaste = _WarnAboutLargePaste;
|
||||
globals->_WarnAboutMultiLinePaste = _WarnAboutMultiLinePaste;
|
||||
globals->_TrimPaste = _TrimPaste;
|
||||
globals->_InitialPosition = _InitialPosition;
|
||||
globals->_CenterOnLaunch = _CenterOnLaunch;
|
||||
globals->_LaunchMode = _LaunchMode;
|
||||
|
@ -201,6 +203,7 @@ void GlobalAppSettings::LayerJson(const Json::Value& json)
|
|||
JsonUtils::GetValueForKey(json, CopyFormattingKey, _CopyFormatting);
|
||||
JsonUtils::GetValueForKey(json, WarnAboutLargePasteKey, _WarnAboutLargePaste);
|
||||
JsonUtils::GetValueForKey(json, WarnAboutMultiLinePasteKey, _WarnAboutMultiLinePaste);
|
||||
JsonUtils::GetValueForKey(json, TrimPasteKey, _TrimPaste);
|
||||
JsonUtils::GetValueForKey(json, FirstWindowPreferenceKey, _FirstWindowPreference);
|
||||
JsonUtils::GetValueForKey(json, LaunchModeKey, _LaunchMode);
|
||||
JsonUtils::GetValueForKey(json, LanguageKey, _Language);
|
||||
|
@ -306,6 +309,7 @@ Json::Value GlobalAppSettings::ToJson() const
|
|||
JsonUtils::SetValueForKey(json, CopyFormattingKey, _CopyFormatting);
|
||||
JsonUtils::SetValueForKey(json, WarnAboutLargePasteKey, _WarnAboutLargePaste);
|
||||
JsonUtils::SetValueForKey(json, WarnAboutMultiLinePasteKey, _WarnAboutMultiLinePaste);
|
||||
JsonUtils::SetValueForKey(json, TrimPasteKey, _TrimPaste);
|
||||
JsonUtils::SetValueForKey(json, FirstWindowPreferenceKey, _FirstWindowPreference);
|
||||
JsonUtils::SetValueForKey(json, LaunchModeKey, _LaunchMode);
|
||||
JsonUtils::SetValueForKey(json, LanguageKey, _Language);
|
||||
|
|
|
@ -77,6 +77,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|||
INHERITABLE_SETTING(Model::GlobalAppSettings, winrt::Microsoft::Terminal::Control::CopyFormat, CopyFormatting, 0);
|
||||
INHERITABLE_SETTING(Model::GlobalAppSettings, bool, WarnAboutLargePaste, true);
|
||||
INHERITABLE_SETTING(Model::GlobalAppSettings, bool, WarnAboutMultiLinePaste, true);
|
||||
INHERITABLE_SETTING(Model::GlobalAppSettings, bool, TrimPaste, true);
|
||||
INHERITABLE_SETTING(Model::GlobalAppSettings, Model::LaunchPosition, InitialPosition, nullptr, nullptr);
|
||||
INHERITABLE_SETTING(Model::GlobalAppSettings, bool, CenterOnLaunch, false);
|
||||
INHERITABLE_SETTING(Model::GlobalAppSettings, Model::FirstWindowPreference, FirstWindowPreference, FirstWindowPreference::DefaultProfile);
|
||||
|
|
|
@ -63,6 +63,7 @@ namespace Microsoft.Terminal.Settings.Model
|
|||
INHERITABLE_SETTING(Microsoft.Terminal.Control.CopyFormat, CopyFormatting);
|
||||
INHERITABLE_SETTING(Boolean, WarnAboutLargePaste);
|
||||
INHERITABLE_SETTING(Boolean, WarnAboutMultiLinePaste);
|
||||
INHERITABLE_SETTING(Boolean, TrimPaste);
|
||||
INHERITABLE_SETTING(LaunchPosition, InitialPosition);
|
||||
INHERITABLE_SETTING(Boolean, CenterOnLaunch);
|
||||
INHERITABLE_SETTING(FirstWindowPreference, FirstWindowPreference);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
"copyOnSelect": false,
|
||||
"copyFormatting": true,
|
||||
"trimBlockSelection": false,
|
||||
"trimPaste": true,
|
||||
"wordDelimiters": " /\\()\"'-.,:;<>~!@#$%^&*|+=[]{}~?\u2502",
|
||||
|
||||
// Tab UI
|
||||
|
|
Loading…
Reference in a new issue