Skip to content

Commit

Permalink
weird but works surprisingly well
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Feb 21, 2024
1 parent 69cb545 commit 17d70f5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
19 changes: 15 additions & 4 deletions src/cascadia/TerminalApp/FilteredCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,22 @@ namespace winrt::TerminalApp::implementation
{
// This class is a wrapper of PaletteItem, that is used as an item of a filterable list in CommandPalette.
// It manages a highlighted text that is computed by matching search filter characters to item name
FilteredCommand::FilteredCommand(const winrt::TerminalApp::PaletteItem& item) :
_Item(item),
_Filter(L""),
_Weight(0)
FilteredCommand::FilteredCommand(const winrt::TerminalApp::PaletteItem& item)
{
// Actually implement the ctor in _constructFilteredCommand
_constructFilteredCommand(item);
}

// We need to actually implement the ctor in a separate helper. This is
// because we have a FilteredTask class which derives from FilteredCommand.
// HOWEVER, for cppwinrt ~ r e a s o n s ~, it doesn't actually derive from
// FilteredCommand directly, so we can't just use the FilteredCommand ctor
// directly in the base class.
void FilteredCommand::_constructFilteredCommand(const winrt::TerminalApp::PaletteItem& item)
{
_Item = item;
_Filter = L"";
_Weight = 0;
_HighlightedName = _computeHighlightedName();

// Recompute the highlighted name if the item name changes
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/FilteredCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ namespace winrt::TerminalApp::implementation
WINRT_OBSERVABLE_PROPERTY(winrt::TerminalApp::HighlightedText, HighlightedName, _PropertyChangedHandlers);
WINRT_OBSERVABLE_PROPERTY(int, Weight, _PropertyChangedHandlers);

protected:
void _constructFilteredCommand(const winrt::TerminalApp::PaletteItem& item);

private:
winrt::TerminalApp::HighlightedText _computeHighlightedName();
int _computeWeight();
Expand Down
6 changes: 4 additions & 2 deletions src/cascadia/TerminalApp/TasksPaneContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace winrt::TerminalApp::implementation

void TasksPaneContent::_updateFilteredCommands()
{
// const auto& queryString = _filterBox().Text();
const auto& queryString = _filterBox().Text();

// You'd think that `FilterToSendInput(queryString)` would work. It
// doesn't! That uses the queryString as the current command the user
Expand All @@ -48,7 +48,9 @@ namespace winrt::TerminalApp::implementation
auto itemSource = winrt::single_threaded_observable_vector<TerminalApp::FilteredTask>();
for (const auto& t : tasks)
{
itemSource.Append(winrt::make<FilteredTask>(t));
const auto& filtered{ winrt::make<FilteredTask>(t) };
filtered.UpdateFilter(queryString);
itemSource.Append(filtered);
}

_treeView().ItemsSource(itemSource);
Expand Down
11 changes: 9 additions & 2 deletions src/cascadia/TerminalApp/TasksPaneContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ namespace winrt::TerminalApp::implementation

FilteredTask(const winrt::Microsoft::Terminal::Settings::Model::Command& command)
{
_constructFilteredCommand(winrt::make<winrt::TerminalApp::implementation::ActionPaletteItem>(command));
_command = command;
_Item = winrt::make<winrt::TerminalApp::implementation::ActionPaletteItem>(command);

// The Children() method must always return a non-null vector
_children = winrt::single_threaded_observable_vector<TerminalApp::FilteredTask>();
Expand All @@ -117,7 +117,14 @@ namespace winrt::TerminalApp::implementation
// FilteredCommand() = default;
// FilteredCommand(const winrt::TerminalApp::PaletteItem& item);

// void UpdateFilter(const winrt::hstring& filter);
void UpdateFilter(const winrt::hstring& filter)
{
TerminalApp::implementation::FilteredCommand::UpdateFilter(filter);
for (const auto& c : _children)
{
c.UpdateFilter(filter);
}
}

// static int Compare(const winrt::TerminalApp::FilteredCommand& first, const winrt::TerminalApp::FilteredCommand& second);

Expand Down
8 changes: 6 additions & 2 deletions src/cascadia/TerminalApp/TasksPaneContent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,15 @@
</Button.Resources>
</Button>

<TextBlock Grid.Column="1"
<!-- <TextBlock Grid.Column="1"
Margin="12,6,0,0"
Style="{ThemeResource BaseTextBlockStyle}"
Text="{x:Bind Item.Name, Mode=OneWay}"
TextWrapping="WrapWholeWords" />
TextWrapping="WrapWholeWords" />-->

<local:HighlightedTextControl Grid.Column="1"
HorizontalAlignment="Left"
Text="{x:Bind HighlightedName, Mode=OneWay}" />
<TextBlock Grid.Row="1"
Grid.Column="1"
Margin="12,0,0,6"
Expand Down

0 comments on commit 17d70f5

Please sign in to comment.