CmdPal: Fixes for the build for the fixes 0.95 (#42279)

Closes #42241
Closes #42245 

Apps that were pinned would show in search results twice. Resolved.

Run & Calculator wouldn't show in search results. Resolved.
This commit is contained in:
Michael Jolley
2025-10-09 22:37:23 -05:00
committed by GitHub
parent 4aa27316fb
commit 075bbb46cb
3 changed files with 62 additions and 61 deletions

View File

@@ -10,6 +10,8 @@ using ManagedCommon;
using Microsoft.CmdPal.Core.Common.Helpers;
using Microsoft.CmdPal.Core.ViewModels.Messages;
using Microsoft.CmdPal.Ext.Apps;
using Microsoft.CmdPal.Ext.Apps.Programs;
using Microsoft.CmdPal.Ext.Apps.State;
using Microsoft.CmdPal.UI.ViewModels.Messages;
using Microsoft.CmdPal.UI.ViewModels.Properties;
using Microsoft.CommandPalette.Extensions;
@@ -36,6 +38,7 @@ public partial class MainListPage : DynamicListPage,
private List<Scored<IListItem>>? _filteredItems;
private List<Scored<IListItem>>? _filteredApps;
private List<Scored<IListItem>>? _fallbackItems;
private IEnumerable<Scored<IListItem>>? _scoredFallbackItems;
private bool _includeApps;
private bool _filteredItemsIncludesApps;
private int _appResultLimit = 10;
@@ -171,6 +174,7 @@ public partial class MainListPage : DynamicListPage,
var items = Enumerable.Empty<Scored<IListItem>>()
.Concat(_filteredItems is not null ? _filteredItems : [])
.Concat(_scoredFallbackItems is not null ? _scoredFallbackItems : [])
.Concat(limitedApps)
.OrderByDescending(o => o.Score)
@@ -184,6 +188,14 @@ public partial class MainListPage : DynamicListPage,
}
}
private void ClearResults()
{
_filteredItems = null;
_filteredApps = null;
_fallbackItems = null;
_scoredFallbackItems = null;
}
public override void UpdateSearchText(string oldSearch, string newSearch)
{
var timer = new Stopwatch();
@@ -216,8 +228,7 @@ public partial class MainListPage : DynamicListPage,
lock (_tlcManager.TopLevelCommands)
{
_filteredItemsIncludesApps = _includeApps;
_filteredItems = null;
_filteredApps = null;
ClearResults();
}
}
@@ -244,9 +255,7 @@ public partial class MainListPage : DynamicListPage,
if (string.IsNullOrEmpty(newSearch))
{
_filteredItemsIncludesApps = _includeApps;
_filteredItems = null;
_filteredApps = null;
_fallbackItems = null;
ClearResults();
RaiseItemsChanged(commands.Count);
return;
}
@@ -255,17 +264,13 @@ public partial class MainListPage : DynamicListPage,
// re-use previous results. Reset _filteredItems, and keep er moving.
if (!newSearch.StartsWith(oldSearch, StringComparison.CurrentCultureIgnoreCase))
{
_filteredItems = null;
_filteredApps = null;
_fallbackItems = null;
ClearResults();
}
// If the internal state has changed, reset _filteredItems to reset the list.
if (_filteredItemsIncludesApps != _includeApps)
{
_filteredItems = null;
_filteredApps = null;
_fallbackItems = null;
ClearResults();
}
if (token.IsCancellationRequested)
@@ -314,7 +319,7 @@ public partial class MainListPage : DynamicListPage,
// We're going to start over with our fallbacks
newFallbacks = Enumerable.Empty<IListItem>();
newFilteredItems = commands.Where(s => !s.IsFallback || _specialFallbacks.Contains(s.CommandProviderId));
newFilteredItems = commands.Where(s => !s.IsFallback);
// Fallbacks are always included in the list, even if they
// don't match the search text. But we don't want to
@@ -330,7 +335,20 @@ public partial class MainListPage : DynamicListPage,
if (_includeApps)
{
newApps = AllAppsCommandProvider.Page.GetItems().ToList();
var allNewApps = AllAppsCommandProvider.Page.GetItems().ToList();
// We need to remove pinned apps from allNewApps so they don't show twice.
var pinnedApps = PinnedAppsManager.Instance.GetPinnedAppIdentifiers();
if (pinnedApps.Length > 0)
{
newApps = allNewApps.Where(w =>
pinnedApps.IndexOf(((AppListItem)w).AppIdentifier) < 0);
}
else
{
newApps = allNewApps;
}
}
if (token.IsCancellationRequested)
@@ -350,6 +368,20 @@ public partial class MainListPage : DynamicListPage,
return;
}
IEnumerable<IListItem> newFallbacksForScoring = commands.Where(s => s.IsFallback && _specialFallbacks.Contains(s.CommandProviderId));
if (token.IsCancellationRequested)
{
return;
}
_scoredFallbackItems = ListHelpers.FilterListWithScores<IListItem>(newFallbacksForScoring ?? [], SearchText, scoreItem);
if (token.IsCancellationRequested)
{
return;
}
// Defaulting scored to 1 but we'll eventually use user rankings
_fallbackItems = [.. newFallbacks.Select(f => new Scored<IListItem> { Item = f, Score = 1 })];