Don't open a hole in the terminal window when pasting (#12208)

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. 5f9c551b7e 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.
This commit is contained in:
Mike Griese
2022-01-27 17:56:31 -06:00
committed by GitHub
parent f8549886f5
commit 95770ed9b2
4 changed files with 10 additions and 11 deletions

View File

@@ -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'; };
@@ -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);

View File

@@ -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);

View File

@@ -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;
};

View File

@@ -30,6 +30,7 @@ namespace Microsoft.Terminal.Control
runtimeclass PasteFromClipboardEventArgs
{
void HandleClipboardData(String data);
Boolean BracketedPasteEnabled { get; };
}
runtimeclass OpenHyperlinkEventArgs