Skip to content

Enable terminal chat message copy #19009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: feature/llm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,5 @@ profiles.json
*.swp

# MSBuildCache
/MSBuildCacheLogs/
/MSBuildCacheLogs/
enc_temp_folder/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, what is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build artifact from vs I think? I thought I modified the gitignore to exclude that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see that is the gitignore. duh. Yea those are some build artifacts that started showing up.

23 changes: 22 additions & 1 deletion src/cascadia/QueryExtension/ExtensionPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "LibraryResources.h"
#include <winrt/Windows.UI.Xaml.Media.Imaging.h>

#include <winrt/Windows.ApplicationModel.DataTransfer.h>

#include "ExtensionPalette.g.cpp"
#include "ChatMessage.g.cpp"
#include "GroupedChatMessages.g.cpp"
Expand All @@ -16,6 +18,7 @@ using namespace winrt::Windows::Foundation::Collections;
using namespace winrt::Windows::UI::Core;
using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Windows::UI::Xaml::Controls;
using namespace winrt::Windows::UI::Xaml::Controls::Primitives;
using namespace winrt::Windows::System;
namespace WWH = ::winrt::Windows::Web::Http;
namespace WSS = ::winrt::Windows::Storage::Streams;
Expand Down Expand Up @@ -340,6 +343,14 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
void ExtensionPalette::_lostFocusHandler(const Windows::Foundation::IInspectable& /*sender*/,
const Windows::UI::Xaml::RoutedEventArgs& /*args*/)
{
const auto focusedElement = Input::FocusManager::GetFocusedElement(this->XamlRoot());
if (focusedElement && (focusedElement.try_as<RichTextBlock>() || focusedElement.try_as<MenuFlyoutPresenter>() || focusedElement.try_as<Popup>()))
{
// The context menu for the message doesn't seem to be found when the VisualTreeHelper walks the visual tree. So we check here
// if one of the focused elements is a message or a context menu of one of those messages and return early to support
// copy and select all using a mouse
return;
}
const auto flyout = _queryBox().ContextFlyout();
if (flyout && flyout.IsOpen())
{
Expand Down Expand Up @@ -404,7 +415,17 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
}
else if (key == VirtualKey::C && ctrlDown)
{
_queryBox().CopySelectionToClipboard();
// Get the focused element. If it is a chat message copy its selection (if any) to the clipboard.
const auto focusedElement = Input::FocusManager::GetFocusedElement(this->XamlRoot());
if (focusedElement && focusedElement.try_as<RichTextBlock>())
{
const auto textBlock = focusedElement.as<RichTextBlock>();
textBlock.CopySelectionToClipboard();
}
else
{
_queryBox().CopySelectionToClipboard();
}
e.Handled(true);
}
else if (key == VirtualKey::V && ctrlDown)
Expand Down
2 changes: 0 additions & 2 deletions src/cascadia/QueryExtension/ExtensionPalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
void _previewKeyDownHandler(const Windows::Foundation::IInspectable& sender,
const Windows::UI::Xaml::Input::KeyRoutedEventArgs& e);
void _setUpAIProviderInSettings(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& args);

void _close();
};

Expand All @@ -67,7 +66,6 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
bool IsQuery() const { return _isQuery; };
winrt::hstring MessageContent() const { return _messageContent; };
winrt::Windows::UI::Xaml::Controls::RichTextBlock RichBlock() const { return _richBlock; };

TYPED_EVENT(RunCommandClicked, winrt::Microsoft::Terminal::Query::Extension::ChatMessage, winrt::hstring);

private:
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/QueryExtension/ExtensionPalette.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="ContextFlyout">
<Setter.Value>
<mtu:TextMenuFlyout />
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
</ListView>
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/QueryExtension/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,4 @@
<value>GitHub Copilot</value>
<comment>The metadata string to display whenever a response is received from the GitHub Copilot service provider</comment>
</data>
</root>
</root>