Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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 x:Name="test" />
Copy link
Member

Choose a reason for hiding this comment

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

We may not need to name this if we don't refer to it by name in the code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
</ListView>
Expand Down
6 changes: 5 additions & 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,8 @@
<value>GitHub Copilot</value>
<comment>The metadata string to display whenever a response is received from the GitHub Copilot service provider</comment>
</data>
</root>
<data name="CopyMessage" xml:space="preserve">
Copy link
Member

Choose a reason for hiding this comment

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

since we're using the existing context menu, we probably don't need this resource either!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kk

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

<value>Copy Message</value>
<comment>Copy terminal chat message</comment>
</data>
</root>
Loading