Make whitespace trimming in block selection configurable (#9807)

## PR Checklist
* [x] Closes https://github.com/microsoft/terminal/issues/9706
* [x] CLA signed.
* [ ] Tests added/passed
* [x] Documentation updated here: https://github.com/MicrosoftDocs/terminal/pull/313
* [x] Schema updated.
* [ ] I've discussed this with core contributors already. 

## Detailed Description of the Pull Request / Additional comments
Added global flag named `trimBlockSelection` set to `false` by default.
The setting was added to Interactions menu of the SUI.
This commit is contained in:
Don-Vito 2021-04-24 01:36:51 +03:00 committed by GitHub
parent 51920d9b46
commit 3d09c7de1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 38 additions and 9 deletions

View file

@ -900,6 +900,11 @@
"description": "When set to `true`, the color and font formatting of selected text is also copied to your clipboard. When set to `false`, only plain text is copied to your clipboard. An array of specific formats can also be used. Supported array values include `html` and `rtf`. Plain text is always copied.",
"$ref": "#/definitions/CopyFormat"
},
"trimBlockSelection": {
"default": false,
"description": "When set to true, trailing white-spaces will be removed from text in rectangular (block) selection while copied to your clipboard. When set to false, the white-spaces will be preserved.",
"type": "boolean"
},
"disableAnimations": {
"default": false,
"description": "When set to `true`, visual animations will be disabled across the application.",

View file

@ -20,6 +20,7 @@ namespace Microsoft.Terminal.Core
String WordDelimiters;
Boolean ForceVTInput;
Boolean TrimBlockSelection;
Windows.Foundation.IReference<Microsoft.Terminal.Core.Color> TabColor;
Windows.Foundation.IReference<Microsoft.Terminal.Core.Color> StartingTabColor;

View file

@ -52,7 +52,8 @@ Terminal::Terminal() :
_blockSelection{ false },
_selection{ std::nullopt },
_taskbarState{ 0 },
_taskbarProgress{ 0 }
_taskbarProgress{ 0 },
_trimBlockSelection{ false }
{
auto dispatch = std::make_unique<TerminalDispatch>(*this);
auto engine = std::make_unique<OutputStateMachineEngine>(std::move(dispatch));
@ -119,6 +120,7 @@ void Terminal::UpdateSettings(ICoreSettings settings)
_wordDelimiters = settings.WordDelimiters();
_suppressApplicationTitle = settings.SuppressApplicationTitle();
_startingTitle = settings.StartingTitle();
_trimBlockSelection = settings.TrimBlockSelection();
_terminalInput->ForceDisableWin32InputMode(settings.ForceVTInput());

View file

@ -264,6 +264,7 @@ private:
bool _altGrAliasing;
bool _suppressApplicationTitle;
bool _bracketedPasteMode;
bool _trimBlockSelection;
size_t _taskbarState;
size_t _taskbarProgress;

View file

@ -255,15 +255,14 @@ const TextBuffer::TextAndColor Terminal::RetrieveSelectedTextFromBuffer(bool sin
const auto GetAttributeColors = std::bind(&Terminal::GetAttributeColors, this, std::placeholders::_1);
// GH#6740: Block selection should preserve the text block as is:
// - No trailing white-spaces should be removed.
// GH#6740: Block selection should preserve the visual structure:
// - CRLFs need to be added - so the lines structure is preserved
// - We should apply formatting above to wrapped rows as well (newline should be added).
return _buffer->GetText(!singleLine || _blockSelection,
!singleLine && !_blockSelection,
selectionRects,
GetAttributeColors,
_blockSelection);
// GH#9706: Trimming of trailing white-spaces in block selection is configurable.
const auto includeCRLF = !singleLine || _blockSelection;
const auto trimTrailingWhitespace = !singleLine && (!_blockSelection || _trimBlockSelection);
const auto formatWrappedRows = _blockSelection;
return _buffer->GetText(includeCRLF, trimTrailingWhitespace, selectionRects, GetAttributeColors, formatWrappedRows);
}
// Method Description:

View file

@ -39,6 +39,11 @@
SelectedItem="{x:Bind CurrentCopyFormat, Mode=TwoWay}" />
</local:SettingContainer>
<!-- Trim Block Selection -->
<local:SettingContainer x:Uid="Globals_TrimBlockSelection">
<ToggleSwitch IsOn="{x:Bind State.Globals.TrimBlockSelection, Mode=TwoWay}" />
</local:SettingContainer>
<!-- Word Delimiters -->
<local:SettingContainer x:Uid="Globals_WordDelimiters">
<TextBox Style="{StaticResource TextBoxSettingStyle}"

View file

@ -209,6 +209,10 @@
<value>Automatically copy selection to clipboard</value>
<comment>Header for a control to toggle whether selected text should be copied to the clipboard automatically, or not.</comment>
</data>
<data name="Globals_TrimBlockSelection.Header" xml:space="preserve">
<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_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>
@ -1065,4 +1069,4 @@
<value>If checked, show all installed fonts in the list above. Otherwise, only show the list of monospace fonts.</value>
<comment>A description for what the supplementary "show all fonts" setting does. Presented near "Profile_FontFaceShowAllFonts".</comment>
</data>
</root>
</root>

View file

@ -45,6 +45,7 @@ static constexpr std::string_view DisableAnimationsKey{ "disableAnimations" };
static constexpr std::string_view StartupActionsKey{ "startupActions" };
static constexpr std::string_view FocusFollowMouseKey{ "focusFollowMouse" };
static constexpr std::string_view WindowingBehaviorKey{ "windowingBehavior" };
static constexpr std::string_view TrimBlockSelectionKey{ "trimBlockSelection" };
static constexpr std::string_view DebugFeaturesKey{ "debugFeatures" };
@ -124,6 +125,7 @@ winrt::com_ptr<GlobalAppSettings> GlobalAppSettings::Copy() const
globals->_StartupActions = _StartupActions;
globals->_FocusFollowMouse = _FocusFollowMouse;
globals->_WindowingBehavior = _WindowingBehavior;
globals->_TrimBlockSelection = _TrimBlockSelection;
globals->_UnparsedDefaultProfile = _UnparsedDefaultProfile;
globals->_validDefaultProfile = _validDefaultProfile;
@ -320,6 +322,8 @@ void GlobalAppSettings::LayerJson(const Json::Value& json)
JsonUtils::GetValueForKey(json, WindowingBehaviorKey, _WindowingBehavior);
JsonUtils::GetValueForKey(json, TrimBlockSelectionKey, _TrimBlockSelection);
// This is a helper lambda to get the keybindings and commands out of both
// and array of objects. We'll use this twice, once on the legacy
// `keybindings` key, and again on the newer `bindings` key.
@ -426,6 +430,7 @@ Json::Value GlobalAppSettings::ToJson() const
JsonUtils::SetValueForKey(json, StartupActionsKey, _StartupActions);
JsonUtils::SetValueForKey(json, FocusFollowMouseKey, _FocusFollowMouse);
JsonUtils::SetValueForKey(json, WindowingBehaviorKey, _WindowingBehavior);
JsonUtils::SetValueForKey(json, TrimBlockSelectionKey, _TrimBlockSelection);
// clang-format on
// TODO GH#8100: keymap needs to be serialized here

View file

@ -91,6 +91,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
INHERITABLE_SETTING(Model::GlobalAppSettings, hstring, StartupActions, L"");
INHERITABLE_SETTING(Model::GlobalAppSettings, bool, FocusFollowMouse, false);
INHERITABLE_SETTING(Model::GlobalAppSettings, Model::WindowingMode, WindowingBehavior, Model::WindowingMode::UseNew);
INHERITABLE_SETTING(Model::GlobalAppSettings, bool, TrimBlockSelection, false);
private:
guid _defaultProfile;

View file

@ -68,6 +68,7 @@ namespace Microsoft.Terminal.Settings.Model
INHERITABLE_SETTING(String, StartupActions);
INHERITABLE_SETTING(Boolean, FocusFollowMouse);
INHERITABLE_SETTING(WindowingMode, WindowingBehavior);
INHERITABLE_SETTING(Boolean, TrimBlockSelection);
Windows.Foundation.Collections.IMapView<String, ColorScheme> ColorSchemes();
void AddColorScheme(ColorScheme scheme);

View file

@ -306,6 +306,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
_ForceFullRepaintRendering = globalSettings.ForceFullRepaintRendering();
_SoftwareRendering = globalSettings.SoftwareRendering();
_ForceVTInput = globalSettings.ForceVTInput();
_TrimBlockSelection = globalSettings.TrimBlockSelection();
}
// Method Description:

View file

@ -94,6 +94,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
INHERITABLE_SETTING(Model::TerminalSettings, bool, CopyOnSelect, false);
INHERITABLE_SETTING(Model::TerminalSettings, bool, InputServiceWarning, true);
INHERITABLE_SETTING(Model::TerminalSettings, bool, FocusFollowMouse, false);
INHERITABLE_SETTING(Model::TerminalSettings, bool, TrimBlockSelection, false);
INHERITABLE_SETTING(Model::TerminalSettings, Windows::Foundation::IReference<Microsoft::Terminal::Core::Color>, TabColor, nullptr);

View file

@ -11,6 +11,7 @@
// Selection
"copyOnSelect": false,
"copyFormatting": true,
"trimBlockSelection": false,
"wordDelimiters": " /\\()\"'-.,:;<>~!@#$%^&*|+=[]{}~?\u2502",
// Tab UI

View file

@ -43,6 +43,7 @@ namespace TerminalCoreUnitTests
ICoreAppearance UnfocusedAppearance() { return {}; };
winrt::Windows::Foundation::IReference<winrt::Microsoft::Terminal::Core::Color> TabColor() { return nullptr; }
winrt::Windows::Foundation::IReference<winrt::Microsoft::Terminal::Core::Color> StartingTabColor() { return nullptr; }
bool TrimBlockSelection() { return false; }
// other implemented methods
til::color GetColorTableEntry(int32_t) const { return 123; }
@ -68,6 +69,7 @@ namespace TerminalCoreUnitTests
void UnfocusedAppearance(ICoreAppearance) {}
void TabColor(const IInspectable&) {}
void StartingTabColor(const IInspectable&) {}
void TrimBlockSelection(bool) {}
private:
int32_t _historySize;