Undo the damage done to FilteredCommand in #17330 (#19148)

PR #17330 changed FilteredCommand so that FilteredTask could derive from
it. It also **did not** implement FilteredTask as a derived class.

We've been carrying around the debt of a decision we un-decided for like
a year.
This commit is contained in:
Dustin L. Howett 2025-07-18 19:09:12 -05:00 committed by GitHub
parent a04e410a39
commit fedf7b3b6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 21 deletions

View File

@ -21,25 +21,11 @@ namespace winrt::TerminalApp::implementation
{ {
// This class is a wrapper of IPaletteItem, that is used as an item of a filterable list in CommandPalette. // This class is a wrapper of IPaletteItem, 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 // It manages a highlighted text that is computed by matching search filter characters to item name
FilteredCommand::FilteredCommand(const winrt::TerminalApp::IPaletteItem& item) FilteredCommand::FilteredCommand(const winrt::TerminalApp::IPaletteItem& item) :
_Item{ item }, _Weight{ 0 }
{ {
// 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::IPaletteItem& item)
{
_Item = item;
_Weight = 0;
_update();
// Recompute the highlighted name if the item name changes // Recompute the highlighted name if the item name changes
// Our Item will not change, so we don't need to update the revoker if it does.
_itemChangedRevoker = _Item.as<winrt::Windows::UI::Xaml::Data::INotifyPropertyChanged>().PropertyChanged(winrt::auto_revoke, [weakThis{ get_weak() }](auto& /*sender*/, auto& e) { _itemChangedRevoker = _Item.as<winrt::Windows::UI::Xaml::Data::INotifyPropertyChanged>().PropertyChanged(winrt::auto_revoke, [weakThis{ get_weak() }](auto& /*sender*/, auto& e) {
auto filteredCommand{ weakThis.get() }; auto filteredCommand{ weakThis.get() };
if (filteredCommand && e.PropertyName() == L"Name") if (filteredCommand && e.PropertyName() == L"Name")

View File

@ -20,7 +20,7 @@ namespace winrt::TerminalApp::implementation
FilteredCommand() = default; FilteredCommand() = default;
FilteredCommand(const winrt::TerminalApp::IPaletteItem& item); FilteredCommand(const winrt::TerminalApp::IPaletteItem& item);
virtual void UpdateFilter(std::shared_ptr<fzf::matcher::Pattern> pattern); void UpdateFilter(std::shared_ptr<fzf::matcher::Pattern> pattern);
static int Compare(const winrt::TerminalApp::FilteredCommand& first, const winrt::TerminalApp::FilteredCommand& second); static int Compare(const winrt::TerminalApp::FilteredCommand& first, const winrt::TerminalApp::FilteredCommand& second);
@ -29,9 +29,6 @@ namespace winrt::TerminalApp::implementation
WINRT_OBSERVABLE_PROPERTY(winrt::Windows::Foundation::Collections::IVector<winrt::TerminalApp::HighlightedRun>, NameHighlights, PropertyChanged.raise); WINRT_OBSERVABLE_PROPERTY(winrt::Windows::Foundation::Collections::IVector<winrt::TerminalApp::HighlightedRun>, NameHighlights, PropertyChanged.raise);
WINRT_OBSERVABLE_PROPERTY(int, Weight, PropertyChanged.raise); WINRT_OBSERVABLE_PROPERTY(int, Weight, PropertyChanged.raise);
protected:
void _constructFilteredCommand(const winrt::TerminalApp::IPaletteItem& item);
private: private:
std::shared_ptr<fzf::matcher::Pattern> _pattern; std::shared_ptr<fzf::matcher::Pattern> _pattern;
void _update(); void _update();