Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect clipboard functionality to their keybindings #1093

Merged
merged 11 commits into from
Jun 25, 2019
10 changes: 10 additions & 0 deletions src/cascadia/TerminalApp/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ namespace winrt::TerminalApp::implementation
bindings.ScrollDownPage([this]() { _ScrollPage(1); });
bindings.SwitchToTab([this](const auto index) { _SelectTab({ index }); });
bindings.OpenSettings([this]() { _OpenSettings(); });
bindings.CopyText([this](const auto trimWhitespace) { _CopyText(trimWhitespace); });
bindings.PasteText([this]() { _PasteText(); });
}

// Method Description:
Expand Down Expand Up @@ -931,6 +933,14 @@ namespace winrt::TerminalApp::implementation
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:
// - Sets focus to the tab to the right or left the currently selected tab.
void App::_SelectNextTab(const bool bMoveRight)
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ namespace winrt::TerminalApp::implementation

void _Scroll(int delta);
void _CopyText(const bool trimTrailingWhitespace);
void _PasteText();
void _SplitVertical(const std::optional<GUID>& profileGuid);
void _SplitHorizontal(const std::optional<GUID>& profileGuid);
void _SplitPane(const Pane::SplitState splitType, const std::optional<GUID>& profileGuid);

// Todo: add more event implementations here
// MSFT:20641986: Add keybindings for New Window
void _ScrollPage(int delta);
Expand Down
5 changes: 4 additions & 1 deletion src/cascadia/TerminalApp/AppKeyBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ namespace winrt::TerminalApp::implementation
switch (action)
{
case ShortcutAction::CopyText:
_CopyTextHandlers();
_CopyTextHandlers(true);
return true;
case ShortcutAction::CopyTextWithoutNewlines:
_CopyTextHandlers(false);
return true;
case ShortcutAction::PasteText:
_PasteTextHandlers();
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalApp/AppKeyBindings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace TerminalApp
enum ShortcutAction
{
CopyText = 0,
CopyTextWithoutNewlines,
PasteText,
NewTab,
NewTabProfile0,
Expand Down Expand Up @@ -42,7 +43,7 @@ namespace TerminalApp
OpenSettings
};

delegate void CopyTextEventArgs();
delegate void CopyTextEventArgs(Boolean trimWhitespace);
delegate void PasteTextEventArgs();
delegate void NewTabEventArgs();
delegate void NewTabWithProfileEventArgs(Int32 profileIndex);
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/AppKeyBindingsSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ static constexpr std::string_view KeysKey{ "keys" };
static constexpr std::string_view CommandKey{ "command" };

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 NewTabKey{ "newTab" };
static constexpr std::string_view NewTabWithProfile0Key{ "newTabProfile0" };
Expand Down Expand Up @@ -60,6 +61,7 @@ static constexpr std::string_view SplitVerticalKey{ "splitVertical" };
// about here.
static const std::map<std::string_view, ShortcutAction, std::less<>> commandNames{
{ CopyTextKey, ShortcutAction::CopyText },
{ CopyTextWithoutNewlinesKey, ShortcutAction::CopyTextWithoutNewlines },
{ PasteTextKey, ShortcutAction::PasteText },
{ NewTabKey, ShortcutAction::NewTab },
{ NewTabWithProfile0Key, ShortcutAction::NewTabProfile0 },
Expand Down
13 changes: 11 additions & 2 deletions src/cascadia/TerminalApp/CascadiaSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,17 @@ void CascadiaSettings::_CreateDefaultKeybindings()
static_cast<int>('T') });

keyBindings.SetKeyBinding(ShortcutAction::CloseTab,
KeyChord{ KeyModifiers::Ctrl,
static_cast<int>('W') });
KeyChord{ KeyModifiers::Ctrl,
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,
KeyChord{ KeyModifiers::Ctrl,
VK_OEM_COMMA });
Expand Down
21 changes: 14 additions & 7 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,13 +715,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// paste selection, otherwise
else
{
// 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);
PasteTextFromClipboard();
}
}
}
Expand Down Expand Up @@ -1167,6 +1161,19 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
_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()
{
if (!_closing.exchange(true))
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation

hstring Title();
void CopySelectionToClipboard(bool trimTrailingWhitespace);
void PasteTextFromClipboard();
void Close();
bool ShouldCloseOnExit() const noexcept;

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/TermControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace Microsoft.Terminal.TerminalControl

String Title { get; };
void CopySelectionToClipboard(Boolean trimTrailingWhitespace);
void PasteTextFromClipboard();
void Close();
Boolean ShouldCloseOnExit { get; };

Expand Down