From ea1bb2ed9359fcc6ded32ad11a8cab544b91ae0e Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Thu, 9 Apr 2020 16:32:38 -0700 Subject: [PATCH] Add 'copyFormatting' global setting (#5299) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary of the Pull Request Implements `copyFormatting` as a global setting. When enabled, formatting such as font and foreground/background colors are copied to the clipboard on _all_ copy operations. Also updates the schema and docs. ## References #5212 - Spec for Formatted Copying #4191 - Setting to enable/disable formatted copy #5263 - PR prematurely merged without approval of #5212 This feature will also have an impact on these yet-to-be-implemented features: - #5262 - copyFormatting Keybinding Arg for Copy - #1553 - Pointer Bindings - #4191 - add array support for `copyFormatting` ## Detailed Description of the Pull Request We already check if the hstring passed into the clipboard is empty before setting it. So the majority of the changes are actually just adding the global setting in. ## Validation Steps Performed | `copyFormatting` | Mouse Copy | Keyboard Copy | |--|--|--| | not set (`false`) | ✔ | ✔ | | `true` | ✔ | ✔ | | `false` | ✔ | ✔ | --- doc/cascadia/SettingsSchema.md | 1 + doc/cascadia/profiles.schema.json | 5 ++++ .../TerminalApp/GlobalAppSettings.cpp | 10 ++++++++ src/cascadia/TerminalApp/GlobalAppSettings.h | 3 +++ src/cascadia/TerminalApp/TerminalPage.cpp | 23 +++++++++++-------- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/doc/cascadia/SettingsSchema.md b/doc/cascadia/SettingsSchema.md index 2775c5b8dd8..bb57aff6579 100644 --- a/doc/cascadia/SettingsSchema.md +++ b/doc/cascadia/SettingsSchema.md @@ -7,6 +7,7 @@ Properties listed below affect the entire window, regardless of the profile sett | -------- | --------- | ---- | ------- | ----------- | | `alwaysShowTabs` | _Required_ | Boolean | `true` | When set to `true`, tabs are always displayed. When set to `false` and `showTabsInTitlebar` is set to `false`, tabs only appear after typing Ctrl + T. | | `copyOnSelect` | Optional | Boolean | `false` | When set to `true`, a selection is immediately copied to your clipboard upon creation. When set to `false`, the selection persists and awaits further action. | +| `copyFormatting` | Optional | Boolean | `false` | 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. | | `defaultProfile` | _Required_ | String | PowerShell guid | Sets the default profile. Opens by typing Ctrl + T or by clicking the '+' icon. The guid of the desired default profile is used as the value. | | `initialCols` | _Required_ | Integer | `120` | The number of columns displayed in the window upon first load. | | `initialPosition` | Optional | String | `","` | The position of the top left corner of the window upon first load. On a system with multiple displays, these coordinates are relative to the top left of the primary display. If `launchMode` is set to `"maximized"`, the window will be maximized on the monitor specified by those coordinates. | diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index 4e19e19c5db..ad9da00eb55 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -277,6 +277,11 @@ "description": "When set to true, a selection is immediately copied to your clipboard upon creation. When set to false, the selection persists and awaits further action.", "type": "boolean" }, + "copyFormatting": { + "default": false, + "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.", + "type": "boolean" + }, "defaultProfile": { "$ref": "#/definitions/ProfileGuid", "description": "Sets the default profile. Opens by clicking the '+' icon or typing the key binding assigned to 'newTab'. The guid of the desired default profile is used as the value." diff --git a/src/cascadia/TerminalApp/GlobalAppSettings.cpp b/src/cascadia/TerminalApp/GlobalAppSettings.cpp index 7d6238cb076..62c814779f1 100644 --- a/src/cascadia/TerminalApp/GlobalAppSettings.cpp +++ b/src/cascadia/TerminalApp/GlobalAppSettings.cpp @@ -32,6 +32,7 @@ static constexpr std::wstring_view TitleLengthTabWidthModeValue{ L"titleLength" static constexpr std::string_view ShowTabsInTitlebarKey{ "showTabsInTitlebar" }; static constexpr std::string_view WordDelimitersKey{ "wordDelimiters" }; static constexpr std::string_view CopyOnSelectKey{ "copyOnSelect" }; +static constexpr std::string_view CopyFormattingKey{ "copyFormatting" }; static constexpr std::string_view LaunchModeKey{ "launchMode" }; static constexpr std::string_view ConfirmCloseAllKey{ "confirmCloseAllTabs" }; static constexpr std::string_view SnapToGridOnResizeKey{ "snapToGridOnResize" }; @@ -67,6 +68,7 @@ GlobalAppSettings::GlobalAppSettings() : _tabWidthMode{ TabViewWidthMode::Equal }, _wordDelimiters{ DEFAULT_WORD_DELIMITERS }, _copyOnSelect{ false }, + _copyFormatting{ false }, _launchMode{ LaunchMode::DefaultMode }, _debugFeatures{ debugFeaturesDefault } { @@ -161,6 +163,11 @@ void GlobalAppSettings::SetCopyOnSelect(const bool copyOnSelect) noexcept _copyOnSelect = copyOnSelect; } +bool GlobalAppSettings::GetCopyFormatting() const noexcept +{ + return _copyFormatting; +} + LaunchMode GlobalAppSettings::GetLaunchMode() const noexcept { return _launchMode; @@ -245,6 +252,7 @@ Json::Value GlobalAppSettings::ToJson() const jsonObject[JsonKey(ShowTabsInTitlebarKey)] = _showTabsInTitlebar; jsonObject[JsonKey(WordDelimitersKey)] = winrt::to_string(_wordDelimiters); jsonObject[JsonKey(CopyOnSelectKey)] = _copyOnSelect; + jsonObject[JsonKey(CopyFormattingKey)] = _copyFormatting; jsonObject[JsonKey(LaunchModeKey)] = winrt::to_string(_SerializeLaunchMode(_launchMode)); jsonObject[JsonKey(ThemeKey)] = winrt::to_string(_SerializeTheme(_theme)); jsonObject[JsonKey(TabWidthModeKey)] = winrt::to_string(_SerializeTabWidthMode(_tabWidthMode)); @@ -311,6 +319,8 @@ void GlobalAppSettings::LayerJson(const Json::Value& json) JsonUtils::GetBool(json, CopyOnSelectKey, _copyOnSelect); + JsonUtils::GetBool(json, CopyFormattingKey, _copyFormatting); + if (auto launchMode{ json[JsonKey(LaunchModeKey)] }) { _launchMode = _ParseLaunchMode(GetWstringFromJson(launchMode)); diff --git a/src/cascadia/TerminalApp/GlobalAppSettings.h b/src/cascadia/TerminalApp/GlobalAppSettings.h index 076b9129471..44435c3d577 100644 --- a/src/cascadia/TerminalApp/GlobalAppSettings.h +++ b/src/cascadia/TerminalApp/GlobalAppSettings.h @@ -68,6 +68,8 @@ class TerminalApp::GlobalAppSettings final bool GetCopyOnSelect() const noexcept; void SetCopyOnSelect(const bool copyOnSelect) noexcept; + bool GetCopyFormatting() const noexcept; + std::optional GetInitialX() const noexcept; std::optional GetInitialY() const noexcept; @@ -110,6 +112,7 @@ class TerminalApp::GlobalAppSettings final bool _showTabsInTitlebar; std::wstring _wordDelimiters; bool _copyOnSelect; + bool _copyFormatting; winrt::Windows::UI::Xaml::ElementTheme _theme; winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode _tabWidthMode; diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 5df4710db4d..a09f0cc8461 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1310,18 +1310,21 @@ namespace winrt::TerminalApp::implementation // copy text to dataPack dataPack.SetText(copiedData.Text()); - // copy html to dataPack - const auto htmlData = copiedData.Html(); - if (!htmlData.empty()) + if (_settings->GlobalSettings().GetCopyFormatting()) { - dataPack.SetHtmlFormat(htmlData); - } + // copy html to dataPack + const auto htmlData = copiedData.Html(); + if (!htmlData.empty()) + { + dataPack.SetHtmlFormat(htmlData); + } - // copy rtf data to dataPack - const auto rtfData = copiedData.Rtf(); - if (!rtfData.empty()) - { - dataPack.SetRtf(rtfData); + // copy rtf data to dataPack + const auto rtfData = copiedData.Rtf(); + if (!rtfData.empty()) + { + dataPack.SetRtf(rtfData); + } } try