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
15 changes: 15 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]() { _CopyText(true); });
d-bingham marked this conversation as resolved.
Show resolved Hide resolved
bindings.PasteText([this]() { _PasteText(); });
}

// Method Description:
Expand Down Expand Up @@ -875,6 +877,19 @@ namespace winrt::TerminalApp::implementation
control.CopySelectionToClipboard(trimTrailingWhitespace);
}

// Method Description:
// - Paste text from the Windows Clipboard to the focused terminal
// Arguments:
// - <none>
d-bingham marked this conversation as resolved.
Show resolved Hide resolved
void App::_PasteText()
{
const int focusedTabIndex = _GetFocusedTabIndex();
std::shared_ptr<Tab> focusedTab{ _tabs[focusedTabIndex] };

const auto control = focusedTab->GetTerminalControl();
d-bingham marked this conversation as resolved.
Show resolved Hide resolved
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
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace winrt::TerminalApp::implementation

void _Scroll(int delta);
void _CopyText(const bool trimTrailingWhitespace);
void _PasteText();
// Todo: add more event implementations here
// MSFT:20641986: Add keybindings for New Window
void _ScrollPage(int delta);
Expand Down
23 changes: 16 additions & 7 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,13 +718,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 @@ -1162,6 +1156,21 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
_clipboardCopyHandlers(copiedData);
}

// Method Description:
// - Initiate a paste operation.
// Arguments:
// - <none>
d-bingham marked this conversation as resolved.
Show resolved Hide resolved
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)
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 @@ -40,6 +40,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation

hstring Title();
void CopySelectionToClipboard(bool trimTrailingWhitespace);
void PasteTextFromClipboard();
void Close();

void ScrollViewport(int viewTop);
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();

void ScrollViewport(Int32 viewTop);
Expand Down