Merging main

This commit is contained in:
Michael Jolley
2025-12-10 21:46:55 -06:00
parent 663d26b202
commit 55ebc3937c
4 changed files with 41 additions and 17 deletions

View File

@@ -34,11 +34,11 @@ public partial class MainListPage : DynamicListPage,
private readonly AppStateModel _appStateModel;
private List<Scored<IListItem>>? _filteredItems;
private List<Scored<IListItem>>? _filteredApps;
private List<Scored<IListItem>>? _fallbackItems;
// Keep as IEnumerable for deferred execution. Fallback item titles are updated
// asynchronously, so scoring must happen lazily when GetItems is called.
private IEnumerable<Scored<IListItem>>? _scoredFallbackItems;
private IEnumerable<Scored<IListItem>>? _fallbackItems;
private bool _includeApps;
private bool _filteredItemsIncludesApps;
private int _appResultLimit = 10;
@@ -166,7 +166,7 @@ public partial class MainListPage : DynamicListPage,
_filteredItems,
_scoredFallbackItems?.ToList(),
_filteredApps,
_fallbackItems,
_fallbackItems?.ToList(),
_appResultLimit);
}
}
@@ -386,6 +386,13 @@ public partial class MainListPage : DynamicListPage,
return;
}
_scoredFallbackItems = ListHelpers.FilterListWithScores<IListItem>(newFallbacksForScoring ?? [], SearchText, scoreItem);
if (token.IsCancellationRequested)
{
return;
}
Func<string, IListItem, int> scoreFallbackItem = (a, b) => { return ScoreFallbackItem(a, b, _settings.FallbackRanks); };
_fallbackItems = [.. ListHelpers.FilterListWithScores<IListItem>(newFallbacks ?? [], SearchText, scoreFallbackItem)];

View File

@@ -29,13 +29,24 @@ internal static class MainListPageResultFactory
}
int len1 = filteredItems?.Count ?? 0;
int len2 = scoredFallbackItems?.Count ?? 0;
// Scored or not, fallbacks may contain empty items that we want to skip.
int len2 = GetNonEmptyFallbackItemsCount(scoredFallbackItems);
// Apps are pre-sorted, so we just need to take the top N, limited by appResultLimit.
int len3 = Math.Min(filteredApps?.Count ?? 0, appResultLimit);
int nonEmptyFallbackCount = GetNonEmptyFallbackItemsCount(fallbackItems);
// Allocate the exact size of the result array.
int totalCount = len1 + len2 + len3 + GetNonEmptyFallbackItemsCount(fallbackItems);
int totalCount = len1 + len2 + len3 + nonEmptyFallbackCount;
// If there are non-empty fallbacks, we'll be adding a separator "Section"
if (nonEmptyFallbackCount > 0)
{
totalCount++;
}
var result = new IListItem[totalCount];
// Three-way stable merge of already-sorted lists.
@@ -122,6 +133,9 @@ internal static class MainListPageResultFactory
// always at the end of the list and are sorted by user settings.
if (fallbackItems is not null)
{
// Create the fallbacks section header
result[writePos++] = new Separator(Properties.Resources.fallbacks);
for (int i = 0; i < fallbackItems.Count; i++)
{
var item = fallbackItems[i].Item;
@@ -143,7 +157,7 @@ internal static class MainListPageResultFactory
{
for (int i = 0; i < fallbackItems.Count; i++)
{
if (!string.IsNullOrEmpty(fallbackItems[i].Item.Title))
if (!string.IsNullOrWhiteSpace(fallbackItems[i].Item.Title))
{
fallbackItemsCount++;
}

View File

@@ -205,7 +205,7 @@ namespace Microsoft.CmdPal.UI.ViewModels.Properties {
}
/// <summary>
/// Looks up a localized string similar to Create a new extension.
/// Looks up a localized string similar to Create extension.
/// </summary>
public static string builtin_create_extension_title {
get {
@@ -349,7 +349,7 @@ namespace Microsoft.CmdPal.UI.ViewModels.Properties {
}
/// <summary>
/// Looks up a localized string similar to Creates a project for a new Command Palette extension.
/// Looks up a localized string similar to Generate a new Command Palette extension project.
/// </summary>
public static string builtin_new_extension_subtitle {
get {
@@ -358,7 +358,7 @@ namespace Microsoft.CmdPal.UI.ViewModels.Properties {
}
/// <summary>
/// Looks up a localized string similar to Open Settings.
/// Looks up a localized string similar to Open Command Palette settings.
/// </summary>
public static string builtin_open_settings_name {
get {
@@ -366,15 +366,6 @@ namespace Microsoft.CmdPal.UI.ViewModels.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Open Command Palette settings.
/// </summary>
public static string builtin_open_settings_subtitle {
get {
return ResourceManager.GetString("builtin_open_settings_subtitle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Exit Command Palette.
/// </summary>
@@ -437,5 +428,14 @@ namespace Microsoft.CmdPal.UI.ViewModels.Properties {
return ResourceManager.GetString("builtin_settings_extension_n_extensions_installed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Fallbacks.
/// </summary>
public static string fallbacks {
get {
return ResourceManager.GetString("fallbacks", resourceCulture);
}
}
}
}

View File

@@ -242,4 +242,7 @@
<data name="builtin_settings_appearance_pick_background_image_title" xml:space="preserve">
<value>Pick background image</value>
</data>
<data name="fallbacks" xml:space="preserve">
<value>Fallbacks</value>
</data>
</root>