From a4f448b3e15344372731bc1c1a095dbdc5b43cc6 Mon Sep 17 00:00:00 2001 From: Michael Jolley Date: Thu, 11 Dec 2025 12:08:56 -0600 Subject: [PATCH] Fixing merge issues --- .github/actions/spell-check/expect.txt | 1 + .../Commands/MainListPage.cs | 12 +++++++++-- .../Commands/MainListPageResultFactory.cs | 20 +++++++++---------- .../MainListPageResultFactoryTests.cs | 10 +++++----- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index f649476f60..380d7dc244 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -1221,6 +1221,7 @@ opensource openxmlformats ollama onnx +openurl OPTIMIZEFORINVOKE ORPHANEDDIALOGTITLE ORSCANS diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPage.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPage.cs index 4f2f116530..2489cd0817 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPage.cs @@ -162,11 +162,19 @@ public partial class MainListPage : DynamicListPage, } else { + var validScoredFallbacks = _scoredFallbackItems? + .Where(s => !string.IsNullOrWhiteSpace(s.Item.Title)) + .ToList(); + + var validFallbacks = _fallbackItems? + .Where(s => !string.IsNullOrWhiteSpace(s.Item.Title)) + .ToList(); + return MainListPageResultFactory.Create( _filteredItems, - _scoredFallbackItems?.ToList(), + validScoredFallbacks, _filteredApps, - _fallbackItems?.ToList(), + validFallbacks, _appResultLimit); } } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPageResultFactory.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPageResultFactory.cs index 464e561640..d63c0e4f90 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPageResultFactory.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPageResultFactory.cs @@ -30,22 +30,17 @@ internal static class MainListPageResultFactory int len1 = filteredItems?.Count ?? 0; - // Scored or not, fallbacks may contain empty items that we want to skip. - int len2 = GetNonEmptyFallbackItemsCount(scoredFallbackItems); + // Empty fallbacks are removed prior to this merge. + int len2 = scoredFallbackItems?.Count ?? 0; // 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); + int nonEmptyFallbackCount = fallbackItems?.Count ?? 0; // Allocate the exact size of the result array. - int totalCount = len1 + len2 + len3 + nonEmptyFallbackCount; - - // If there are non-empty fallbacks, we'll be adding a separator "Section" - if (nonEmptyFallbackCount > 0) - { - totalCount++; - } + // We'll add an extra slot for the fallbacks section header if needed. + int totalCount = len1 + len2 + len3 + nonEmptyFallbackCount + (nonEmptyFallbackCount > 0 ? 1 : 0); var result = new IListItem[totalCount]; @@ -134,7 +129,10 @@ internal static class MainListPageResultFactory if (fallbackItems is not null) { // Create the fallbacks section header - result[writePos++] = new Separator(Properties.Resources.fallbacks); + if (fallbackItems.Count > 0) + { + result[writePos++] = new Separator(Properties.Resources.fallbacks); + } for (int i = 0; i < fallbackItems.Count; i++) { diff --git a/src/modules/cmdpal/Tests/Microsoft.CmdPal.UI.ViewModels.UnitTests/MainListPageResultFactoryTests.cs b/src/modules/cmdpal/Tests/Microsoft.CmdPal.UI.ViewModels.UnitTests/MainListPageResultFactoryTests.cs index 624fa2da73..5a1e4bff54 100644 --- a/src/modules/cmdpal/Tests/Microsoft.CmdPal.UI.ViewModels.UnitTests/MainListPageResultFactoryTests.cs +++ b/src/modules/cmdpal/Tests/Microsoft.CmdPal.UI.ViewModels.UnitTests/MainListPageResultFactoryTests.cs @@ -96,7 +96,7 @@ public partial class MainListPageResultFactoryTests var titles = result.Select(r => r.Title).ToArray(); #pragma warning disable CA1861 // Avoid constant arrays as arguments CollectionAssert.AreEqual( - new[] { "F1", "SF1", "A1", "SF2", "A2", "F2", "FB1", "FB2" }, + new[] { "F1", "SF1", "A1", "SF2", "A2", "F2", "Fallbacks", "FB1", "FB2" }, titles); #pragma warning restore CA1861 // Avoid constant arrays as arguments } @@ -129,7 +129,6 @@ public partial class MainListPageResultFactoryTests var fallbacks = new List> { S("FB1", 0), - S(string.Empty, 0), S("FB3", 0), }; @@ -140,9 +139,10 @@ public partial class MainListPageResultFactoryTests fallbacks, appResultLimit: 10); - Assert.AreEqual(2, result.Length); - Assert.AreEqual("FB1", result[0].Title); - Assert.AreEqual("FB3", result[1].Title); + Assert.AreEqual(3, result.Length); + Assert.AreEqual("Fallbacks", result[0].Title); + Assert.AreEqual("FB1", result[1].Title); + Assert.AreEqual("FB3", result[2].Title); } [TestMethod]