Repository: microsoft/terminal (language: cpp)

Issue:
Pasting multiple lines in bracketed paste mode creates a giant transparent hole
version 1.13.whatever we're selfhosting

1. open WSL
2. open a file in vim
3. copy some text with multiple lines and a trailing newline from anywhere, like 
```
[interop]
appendWindowsPath = false

```
4. paste into vim with an action / right click

actual behavior:

Whatever the heck this is:
![2d93f07d-80ca-4245-a404-288880e4c898](https://user-images.githubusercontent.com/18356694/150207028-1958507e-37bc-4c04-9614-828b026114b8.jpg)

![d0c194fe-af42-44f1-a05e-948ed8264e30](https://user-images.githubusercontent.com/18356694/150207016-2beed574-8895-4241-9b2d-d9dcb6f82a08.jpg)
![43304fc1-2169-466d-80b8-950509dfb8c2](https://user-images.githubusercontent.com/18356694/150207059-98525f1d-ff44-4fb0-9d24-0e8dbde93288.jpg)
![e27769d2-3ada-40f5-b80d-c0d33524086d](https://user-images.githubusercontent.com/18356694/150207110-f7f4e8a2-ae64-432f-ac31-3688ced0ac79.jpg)


Presumably this is interaction with the paste trimming and bracketed paste, just not clear... how... 



Discussion / hints:

Fix patch:
diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp
index 4d0e4584054..77b877f7cfb 100644
--- a/src/cascadia/TerminalApp/TerminalPage.cpp
+++ b/src/cascadia/TerminalApp/TerminalPage.cpp
@@ -1970,7 +1970,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'; };
@@ -1986,13 +1988,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);
diff --git a/src/cascadia/TerminalControl/ControlInteractivity.cpp b/src/cascadia/TerminalControl/ControlInteractivity.cpp
index 70c34674a8f..de992e1b379 100644
--- a/src/cascadia/TerminalControl/ControlInteractivity.cpp
+++ b/src/cascadia/TerminalControl/ControlInteractivity.cpp
@@ -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);
diff --git a/src/cascadia/TerminalControl/EventArgs.h b/src/cascadia/TerminalControl/EventArgs.h
index 27dc2c6473f..9f76c061cb3 100644
--- a/src/cascadia/TerminalControl/EventArgs.h
+++ b/src/cascadia/TerminalControl/EventArgs.h
@@ -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;
     };
diff --git a/src/cascadia/TerminalControl/EventArgs.idl b/src/cascadia/TerminalControl/EventArgs.idl
index dae093f51f8..f81a4153ba5 100644
--- a/src/cascadia/TerminalControl/EventArgs.idl
+++ b/src/cascadia/TerminalControl/EventArgs.idl
@@ -30,6 +30,7 @@ namespace Microsoft.Terminal.Control
     runtimeclass PasteFromClipboardEventArgs
     {
         void HandleClipboardData(String data);
+        Boolean BracketedPasteEnabled { get; };
     }
 
     runtimeclass OpenHyperlinkEventArgs


Test patch: