Connect clipboard functionality to their keybindings (#1093)

* Connects clipboard functionality to their keybindings.

* Cleaning up comments and whitespace.

* Added "copyTextWithoutNewlines" keybinding.

* Fixing tabs in idl file

* Fixing merge conflicts

* Adding default keybindings for copy and paste to ctrl-shift-c and ctrl-shift-v, respectively.

* Complying with refactoring

* Fixing formatting issues
This commit is contained in:
d-bingham 2019-06-25 14:17:02 -05:00 committed by Kayla Cinnamon
parent b9e66fee6d
commit b115799810
9 changed files with 45 additions and 9 deletions

View file

@ -503,6 +503,8 @@ namespace winrt::TerminalApp::implementation
bindings.ScrollDownPage([this]() { _ScrollPage(1); }); bindings.ScrollDownPage([this]() { _ScrollPage(1); });
bindings.SwitchToTab([this](const auto index) { _SelectTab({ index }); }); bindings.SwitchToTab([this](const auto index) { _SelectTab({ index }); });
bindings.OpenSettings([this]() { _OpenSettings(); }); bindings.OpenSettings([this]() { _OpenSettings(); });
bindings.CopyText([this](const auto trimWhitespace) { _CopyText(trimWhitespace); });
bindings.PasteText([this]() { _PasteText(); });
} }
// Method Description: // Method Description:
@ -1015,6 +1017,14 @@ namespace winrt::TerminalApp::implementation
control.CopySelectionToClipboard(trimTrailingWhitespace); control.CopySelectionToClipboard(trimTrailingWhitespace);
} }
// Method Description:
// - Paste text from the Windows Clipboard to the focused terminal
void App::_PasteText()
{
const auto control = _GetFocusedControl();
control.PasteTextFromClipboard();
}
// Method Description: // Method Description:
// - Sets focus to the tab to the right or left the currently selected tab. // - Sets focus to the tab to the right or left the currently selected tab.
void App::_SelectNextTab(const bool bMoveRight) void App::_SelectNextTab(const bool bMoveRight)

View file

@ -112,9 +112,11 @@ namespace winrt::TerminalApp::implementation
void _Scroll(int delta); void _Scroll(int delta);
void _CopyText(const bool trimTrailingWhitespace); void _CopyText(const bool trimTrailingWhitespace);
void _PasteText();
void _SplitVertical(const std::optional<GUID>& profileGuid); void _SplitVertical(const std::optional<GUID>& profileGuid);
void _SplitHorizontal(const std::optional<GUID>& profileGuid); void _SplitHorizontal(const std::optional<GUID>& profileGuid);
void _SplitPane(const Pane::SplitState splitType, const std::optional<GUID>& profileGuid); void _SplitPane(const Pane::SplitState splitType, const std::optional<GUID>& profileGuid);
// Todo: add more event implementations here // Todo: add more event implementations here
// MSFT:20641986: Add keybindings for New Window // MSFT:20641986: Add keybindings for New Window
void _ScrollPage(int delta); void _ScrollPage(int delta);

View file

@ -47,7 +47,10 @@ namespace winrt::TerminalApp::implementation
switch (action) switch (action)
{ {
case ShortcutAction::CopyText: case ShortcutAction::CopyText:
_CopyTextHandlers(); _CopyTextHandlers(true);
return true;
case ShortcutAction::CopyTextWithoutNewlines:
_CopyTextHandlers(false);
return true; return true;
case ShortcutAction::PasteText: case ShortcutAction::PasteText:
_PasteTextHandlers(); _PasteTextHandlers();

View file

@ -6,6 +6,7 @@ namespace TerminalApp
enum ShortcutAction enum ShortcutAction
{ {
CopyText = 0, CopyText = 0,
CopyTextWithoutNewlines,
PasteText, PasteText,
NewTab, NewTab,
NewTabProfile0, NewTabProfile0,
@ -42,7 +43,7 @@ namespace TerminalApp
OpenSettings OpenSettings
}; };
delegate void CopyTextEventArgs(); delegate void CopyTextEventArgs(Boolean trimWhitespace);
delegate void PasteTextEventArgs(); delegate void PasteTextEventArgs();
delegate void NewTabEventArgs(); delegate void NewTabEventArgs();
delegate void NewTabWithProfileEventArgs(Int32 profileIndex); delegate void NewTabWithProfileEventArgs(Int32 profileIndex);

View file

@ -14,6 +14,7 @@ static constexpr std::string_view KeysKey{ "keys" };
static constexpr std::string_view CommandKey{ "command" }; static constexpr std::string_view CommandKey{ "command" };
static constexpr std::string_view CopyTextKey{ "copy" }; static constexpr std::string_view CopyTextKey{ "copy" };
static constexpr std::string_view CopyTextWithoutNewlinesKey{ "copyTextWithoutNewlines" };
static constexpr std::string_view PasteTextKey{ "paste" }; static constexpr std::string_view PasteTextKey{ "paste" };
static constexpr std::string_view NewTabKey{ "newTab" }; static constexpr std::string_view NewTabKey{ "newTab" };
static constexpr std::string_view NewTabWithProfile0Key{ "newTabProfile0" }; static constexpr std::string_view NewTabWithProfile0Key{ "newTabProfile0" };
@ -60,6 +61,7 @@ static constexpr std::string_view SplitVerticalKey{ "splitVertical" };
// about here. // about here.
static const std::map<std::string_view, ShortcutAction, std::less<>> commandNames{ static const std::map<std::string_view, ShortcutAction, std::less<>> commandNames{
{ CopyTextKey, ShortcutAction::CopyText }, { CopyTextKey, ShortcutAction::CopyText },
{ CopyTextWithoutNewlinesKey, ShortcutAction::CopyTextWithoutNewlines },
{ PasteTextKey, ShortcutAction::PasteText }, { PasteTextKey, ShortcutAction::PasteText },
{ NewTabKey, ShortcutAction::NewTab }, { NewTabKey, ShortcutAction::NewTab },
{ NewTabWithProfile0Key, ShortcutAction::NewTabProfile0 }, { NewTabWithProfile0Key, ShortcutAction::NewTabProfile0 },

View file

@ -257,6 +257,15 @@ void CascadiaSettings::_CreateDefaultKeybindings()
keyBindings.SetKeyBinding(ShortcutAction::CloseTab, keyBindings.SetKeyBinding(ShortcutAction::CloseTab,
KeyChord{ KeyModifiers::Ctrl, KeyChord{ KeyModifiers::Ctrl,
static_cast<int>('W') }); static_cast<int>('W') });
keyBindings.SetKeyBinding(ShortcutAction::CopyText,
KeyChord{ KeyModifiers::Ctrl | KeyModifiers::Shift,
static_cast<int>('C') });
keyBindings.SetKeyBinding(ShortcutAction::PasteText,
KeyChord{ KeyModifiers::Ctrl | KeyModifiers::Shift,
static_cast<int>('V') });
keyBindings.SetKeyBinding(ShortcutAction::OpenSettings, keyBindings.SetKeyBinding(ShortcutAction::OpenSettings,
KeyChord{ KeyModifiers::Ctrl, KeyChord{ KeyModifiers::Ctrl,
VK_OEM_COMMA }); VK_OEM_COMMA });

View file

@ -721,13 +721,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// paste selection, otherwise // paste selection, otherwise
else else
{ {
// attach TermControl::_SendInputToConnection() as the clipboardDataHandler. PasteTextFromClipboard();
// This is called when the clipboard data is loaded.
auto clipboardDataHandler = std::bind(&TermControl::_SendInputToConnection, this, std::placeholders::_1);
auto pasteArgs = winrt::make_self<PasteFromClipboardEventArgs>(clipboardDataHandler);
// send paste event up to TermApp
_clipboardPasteHandlers(*this, *pasteArgs);
} }
} }
} }
@ -1209,6 +1203,19 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
_clipboardCopyHandlers(copiedData); _clipboardCopyHandlers(copiedData);
} }
// Method Description:
// - Initiate a paste operation.
void TermControl::PasteTextFromClipboard()
{
// attach TermControl::_SendInputToConnection() as the clipboardDataHandler.
// This is called when the clipboard data is loaded.
auto clipboardDataHandler = std::bind(&TermControl::_SendInputToConnection, this, std::placeholders::_1);
auto pasteArgs = winrt::make_self<PasteFromClipboardEventArgs>(clipboardDataHandler);
// send paste event up to TermApp
_clipboardPasteHandlers(*this, *pasteArgs);
}
void TermControl::Close() void TermControl::Close()
{ {
if (!_closing.exchange(true)) if (!_closing.exchange(true))

View file

@ -41,6 +41,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
hstring Title(); hstring Title();
void CopySelectionToClipboard(bool trimTrailingWhitespace); void CopySelectionToClipboard(bool trimTrailingWhitespace);
void PasteTextFromClipboard();
void Close(); void Close();
bool ShouldCloseOnExit() const noexcept; bool ShouldCloseOnExit() const noexcept;

View file

@ -32,6 +32,7 @@ namespace Microsoft.Terminal.TerminalControl
String Title { get; }; String Title { get; };
void CopySelectionToClipboard(Boolean trimTrailingWhitespace); void CopySelectionToClipboard(Boolean trimTrailingWhitespace);
void PasteTextFromClipboard();
void Close(); void Close();
Boolean ShouldCloseOnExit { get; }; Boolean ShouldCloseOnExit { get; };