Improve clipboard handling in "drag and drop" scenario (#8461)

This PR improves the clipboard handling logic of "drag and drop" in
TermControl, making it more useful and less likely to crash.

* Added support for two more categories of content, `ApplicationLink`
  and `WebLink`.
* Reordered the ifs, making `StorageItem` the last clause. With WT being
  a text-oriented application, I think we can safely assume that the
  content being pasted is likely to be text/links.
* Catch possible exceptions during
  `e.DataView().GetStorageItemsAsync()`.

Closes #7804
This commit is contained in:
Chester Liu 2020-12-03 07:30:52 +08:00 committed by GitHub
parent d3bcd85900
commit 60f1b0b285
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2946,9 +2946,46 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
return;
}
if (e.DataView().Contains(StandardDataFormats::StorageItems()))
if (e.DataView().Contains(StandardDataFormats::ApplicationLink()))
{
auto items = co_await e.DataView().GetStorageItemsAsync();
try
{
Windows::Foundation::Uri link{ co_await e.DataView().GetApplicationLinkAsync() };
_SendPastedTextToConnection(std::wstring{ link.AbsoluteUri() });
}
CATCH_LOG();
}
else if (e.DataView().Contains(StandardDataFormats::WebLink()))
{
try
{
Windows::Foundation::Uri link{ co_await e.DataView().GetWebLinkAsync() };
_SendPastedTextToConnection(std::wstring{ link.AbsoluteUri() });
}
CATCH_LOG();
}
else if (e.DataView().Contains(StandardDataFormats::Text()))
{
try
{
std::wstring text{ co_await e.DataView().GetTextAsync() };
_SendPastedTextToConnection(text);
}
CATCH_LOG();
}
// StorageItem must be last. Some applications put hybrid data format items
// in a drop message and we'll eat a crash when we request them.
// Those applications usually include Text as well, so having storage items
// last makes sure we'll hit text before getting to them.
else if (e.DataView().Contains(StandardDataFormats::StorageItems()))
{
Windows::Foundation::Collections::IVectorView<Windows::Storage::IStorageItem> items;
try
{
items = co_await e.DataView().GetStorageItemsAsync();
}
CATCH_LOG();
if (items.Size() > 0)
{
std::wstring allPaths;
@ -2978,15 +3015,6 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
_SendInputToConnection(allPaths);
}
}
else if (e.DataView().Contains(StandardDataFormats::Text()))
{
try
{
std::wstring text{ co_await e.DataView().GetTextAsync() };
_SendPastedTextToConnection(text);
}
CATCH_LOG();
}
}
// Method Description: