Fix #6079, allow pasting from Explorer's 'Copy Address' (#6146)

Fixes #6079 by implementing support for IStorageItem clipboard contents. Manually tested, seems to work for both types of address-copying from Explorer (as well as normal text).

## PR Checklist
* [x] Closes #6079
* Not sure what tests would be useful here, it's mostly to do with what Explorer's doing

Not enormously familiar with C++ or this codebase, so happy to make changes as requested.

## Validation Steps Performed

Ran the terminal, pasted from several different sources (explorer's various copy functions + plaintext)
This commit is contained in:
Alex Hicks 2020-05-27 13:42:49 -04:00 committed by GitHub
parent 0582a6576a
commit f1b67b3683
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,6 +11,7 @@
#include <LibraryResources.h>
#include "TerminalPage.g.cpp"
#include <winrt/Windows.Storage.h>
#include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h>
#include "AzureCloudShellGenerator.h" // For AzureConnectionType
@ -1468,6 +1469,16 @@ namespace winrt::TerminalApp::implementation
{
text = co_await data.GetTextAsync();
}
// Windows Explorer's "Copy address" menu item stores a StorageItem in the clipboard, and no text.
else if (data.Contains(StandardDataFormats::StorageItems()))
{
Windows::Foundation::Collections::IVectorView<Windows::Storage::IStorageItem> items = co_await data.GetStorageItemsAsync();
if (items.Size() > 0)
{
Windows::Storage::IStorageItem item = items.GetAt(0);
text = item.Path();
}
}
eventArgs.HandleClipboardData(text);
}
CATCH_LOG();