Added: Copy text without dismissing the selection (#15552)
## Summary of the Pull Request Adds a dismiss selection option to the "copy" action. ## PR Checklist - [x] Closes #15371 - [x] Tests added/passed - [x] Documentation updated - If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: MicrosoftDocs/terminal#686 - [x] Schema updated (if necessary) --------- Co-authored-by: Carlos Zamora <carlos.zamora@microsoft.com>
This commit is contained in:
parent
167819a8f4
commit
0c64b8a105
|
@ -799,6 +799,11 @@
|
|||
"default": false,
|
||||
"description": "If true, the copied content will be copied as a single line (even if there are hard line breaks present in the text). If false, newlines persist from the selected text."
|
||||
},
|
||||
"dismissSelection": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "If false, the copied content will be copied and the selection will not be dismissed. If true, the selection will be dismissed."
|
||||
},
|
||||
"copyFormatting": {
|
||||
"default": null,
|
||||
"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. Not setting this value inherits the behavior of the `copyFormatting` global setting.",
|
||||
|
|
|
@ -512,7 +512,7 @@ namespace winrt::TerminalApp::implementation
|
|||
{
|
||||
if (const auto& realArgs = args.ActionArgs().try_as<CopyTextArgs>())
|
||||
{
|
||||
const auto handled = _CopyText(realArgs.SingleLine(), realArgs.CopyFormatting());
|
||||
const auto handled = _CopyText(realArgs.DismissSelection(), realArgs.SingleLine(), realArgs.CopyFormatting());
|
||||
args.Handled(handled);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2748,15 +2748,16 @@ namespace winrt::TerminalApp::implementation
|
|||
// Method Description:
|
||||
// - Copy text from the focused terminal to the Windows Clipboard
|
||||
// Arguments:
|
||||
// - dismissSelection: if not enabled, copying text doesn't dismiss the selection
|
||||
// - singleLine: if enabled, copy contents as a single line of text
|
||||
// - formats: dictate which formats need to be copied
|
||||
// Return Value:
|
||||
// - true iff we we able to copy text (if a selection was active)
|
||||
bool TerminalPage::_CopyText(const bool singleLine, const Windows::Foundation::IReference<CopyFormat>& formats)
|
||||
bool TerminalPage::_CopyText(const bool dismissSelection, const bool singleLine, const Windows::Foundation::IReference<CopyFormat>& formats)
|
||||
{
|
||||
if (const auto& control{ _GetActiveControl() })
|
||||
{
|
||||
return control.CopySelectionToClipboard(singleLine, formats);
|
||||
return control.CopySelectionToClipboard(dismissSelection, singleLine, formats);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -410,7 +410,7 @@ namespace winrt::TerminalApp::implementation
|
|||
bool _IsUriSupported(const winrt::Windows::Foundation::Uri& parsedUri);
|
||||
|
||||
void _ShowCouldNotOpenDialog(winrt::hstring reason, winrt::hstring uri);
|
||||
bool _CopyText(const bool singleLine, const Windows::Foundation::IReference<Microsoft::Terminal::Control::CopyFormat>& formats);
|
||||
bool _CopyText(const bool dismissSelection, const bool singleLine, const Windows::Foundation::IReference<Microsoft::Terminal::Control::CopyFormat>& formats);
|
||||
|
||||
winrt::fire_and_forget _SetTaskbarProgressHandler(const IInspectable sender, const IInspectable eventArgs);
|
||||
|
||||
|
|
|
@ -2066,10 +2066,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
|||
// Windows Clipboard (CascadiaWin32:main.cpp).
|
||||
// - CopyOnSelect does NOT clear the selection
|
||||
// Arguments:
|
||||
// - dismissSelection: dismiss the text selection after copy
|
||||
// - singleLine: collapse all of the text to one line
|
||||
// - formats: which formats to copy (defined by action's CopyFormatting arg). nullptr
|
||||
// if we should defer which formats are copied to the global setting
|
||||
bool TermControl::CopySelectionToClipboard(bool singleLine, const Windows::Foundation::IReference<CopyFormat>& formats)
|
||||
bool TermControl::CopySelectionToClipboard(bool dismissSelection, bool singleLine, const Windows::Foundation::IReference<CopyFormat>& formats)
|
||||
{
|
||||
if (_IsClosing())
|
||||
{
|
||||
|
@ -2077,7 +2078,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
|||
}
|
||||
|
||||
const auto successfulCopy = _interactivity.CopySelectionToClipboard(singleLine, formats);
|
||||
_core.ClearSelection();
|
||||
|
||||
if (dismissSelection)
|
||||
{
|
||||
_core.ClearSelection();
|
||||
}
|
||||
|
||||
return successfulCopy;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
|||
|
||||
hstring GetProfileName() const;
|
||||
|
||||
bool CopySelectionToClipboard(bool singleLine, const Windows::Foundation::IReference<CopyFormat>& formats);
|
||||
bool CopySelectionToClipboard(bool dismissSelection, bool singleLine, const Windows::Foundation::IReference<CopyFormat>& formats);
|
||||
void PasteTextFromClipboard();
|
||||
void SelectAll();
|
||||
bool ToggleBlockSelection();
|
||||
|
|
|
@ -67,7 +67,7 @@ namespace Microsoft.Terminal.Control
|
|||
event Windows.Foundation.TypedEventHandler<Object, Object> CloseTerminalRequested;
|
||||
event Windows.Foundation.TypedEventHandler<Object, Object> RestartTerminalRequested;
|
||||
|
||||
Boolean CopySelectionToClipboard(Boolean singleLine, Windows.Foundation.IReference<CopyFormat> formats);
|
||||
Boolean CopySelectionToClipboard(Boolean dismissSelection, Boolean singleLine, Windows.Foundation.IReference<CopyFormat> formats);
|
||||
void PasteTextFromClipboard();
|
||||
void SelectAll();
|
||||
Boolean ToggleBlockSelection();
|
||||
|
|
|
@ -197,6 +197,11 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|||
ss << RS_(L"CopyTextCommandKey").c_str();
|
||||
}
|
||||
|
||||
if (!DismissSelection())
|
||||
{
|
||||
ss << L", dismissSelection: false";
|
||||
}
|
||||
|
||||
if (CopyFormatting())
|
||||
{
|
||||
ss << L", copyFormatting: ";
|
||||
|
|
|
@ -100,8 +100,9 @@ private: \
|
|||
// false, if we don't really care if the parameter is required or not.
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#define COPY_TEXT_ARGS(X) \
|
||||
X(bool, SingleLine, "singleLine", false, false) \
|
||||
#define COPY_TEXT_ARGS(X) \
|
||||
X(bool, DismissSelection, "dismissSelection", false, true) \
|
||||
X(bool, SingleLine, "singleLine", false, false) \
|
||||
X(Windows::Foundation::IReference<Control::CopyFormat>, CopyFormatting, "copyFormatting", false, nullptr)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -155,6 +155,7 @@ namespace Microsoft.Terminal.Settings.Model
|
|||
[default_interface] runtimeclass CopyTextArgs : IActionArgs
|
||||
{
|
||||
CopyTextArgs();
|
||||
Boolean DismissSelection { get; };
|
||||
Boolean SingleLine { get; };
|
||||
Windows.Foundation.IReference<Microsoft.Terminal.Control.CopyFormat> CopyFormatting { get; };
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue