Skip to content

Commit

Permalink
Don't open a hole in the terminal window when pasting (#12208)
Browse files Browse the repository at this point in the history
Turns out, this bug only repros in Controls version 2. I'm not sure why, but it didn't repro only on main. So this fix does nothing until #11720 merges.

This PR prevents us from setting properties on the paste warning dialog unless we actually need to paste. 5f9c551 proves that settings these properties is what would cause the bug in the first place. 

I went a step further and cleaned this up a bit. This was always a little weird, having to get the `BracketedPasteEnabled` for the active control on the UI thread before we actually display the warning. In the post-#5000 future where going back to the control like this would be a x-proc hop, I figured I should just skip that entirely and plumb the `BracketedPaste` state out in the initial request. 

* [x] Closes #12202
* [x] I work here
* [x] No tests, but there's not a great place for a test like this
* [x] Doesn't affect docs

See also: #12241 which would introduce #12202 on its own.
  • Loading branch information
zadjii-msft authored Jan 27, 2022
1 parent f854988 commit 95770ed
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
11 changes: 3 additions & 8 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2136,7 +2136,9 @@ namespace winrt::TerminalApp::implementation
}
}

bool warnMultiLine = _settings.GlobalSettings().WarnAboutMultiLinePaste();
// If the requesting terminal is in bracketed paste mode, then we don't need to warn about a multi-line paste.
bool warnMultiLine = _settings.GlobalSettings().WarnAboutMultiLinePaste() &&
!eventArgs.BracketedPasteEnabled();
if (warnMultiLine)
{
const auto isNewLineLambda = [](auto c) { return c == L'\n' || c == L'\r'; };
Expand All @@ -2152,13 +2154,6 @@ namespace winrt::TerminalApp::implementation
{
co_await winrt::resume_foreground(Dispatcher());

if (warnMultiLine)
{
const auto focusedTab = _GetFocusedTabImpl();
// Do not warn about multi line pasting if the current tab has bracketed paste enabled.
warnMultiLine = warnMultiLine && !focusedTab->GetActiveTerminalControl().BracketedPasteEnabled();
}

// We have to initialize the dialog here to be able to change the text of the text block within it
FindName(L"MultiLinePasteDialog").try_as<WUX::Controls::ContentDialog>();
ClipboardText().Text(text);
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalControl/ControlInteractivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// clipboardDataHandler. This is called when the clipboard data is
// loaded.
auto clipboardDataHandler = std::bind(&ControlInteractivity::_sendPastedTextToConnection, this, std::placeholders::_1);
auto pasteArgs = winrt::make_self<PasteFromClipboardEventArgs>(clipboardDataHandler);
auto pasteArgs = winrt::make_self<PasteFromClipboardEventArgs>(clipboardDataHandler, _core->BracketedPasteEnabled());

// send paste event up to TermApp
_PasteFromClipboardHandlers(*this, *pasteArgs);
Expand Down
7 changes: 5 additions & 2 deletions src/cascadia/TerminalControl/EventArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ namespace winrt::Microsoft::Terminal::Control::implementation
struct PasteFromClipboardEventArgs : public PasteFromClipboardEventArgsT<PasteFromClipboardEventArgs>
{
public:
PasteFromClipboardEventArgs(std::function<void(std::wstring_view)> clipboardDataHandler) :
m_clipboardDataHandler(clipboardDataHandler) {}
PasteFromClipboardEventArgs(std::function<void(std::wstring_view)> clipboardDataHandler, bool bracketedPasteEnabled) :
m_clipboardDataHandler(clipboardDataHandler),
_BracketedPasteEnabled{ bracketedPasteEnabled } {}

void HandleClipboardData(hstring value)
{
m_clipboardDataHandler(value);
};

WINRT_PROPERTY(bool, BracketedPasteEnabled, false);

private:
std::function<void(std::wstring_view)> m_clipboardDataHandler;
};
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/EventArgs.idl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace Microsoft.Terminal.Control
runtimeclass PasteFromClipboardEventArgs
{
void HandleClipboardData(String data);
Boolean BracketedPasteEnabled { get; };
}

runtimeclass OpenHyperlinkEventArgs
Expand Down

0 comments on commit 95770ed

Please sign in to comment.