From def9310e7ecff4dd0dcc7214abd928b05795efc5 Mon Sep 17 00:00:00 2001 From: Lawrence Chen <54008264+lawrencecchen@users.noreply.github.com> Date: Fri, 6 Mar 2026 04:28:40 -0800 Subject: [PATCH] Fix command preview search for new queries --- Sources/ContentView.swift | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Sources/ContentView.swift b/Sources/ContentView.swift index 9701ca2e..3ccfed8f 100644 --- a/Sources/ContentView.swift +++ b/Sources/ContentView.swift @@ -3380,6 +3380,8 @@ struct ContentView: View { } let previewMatches = Self.commandPalettePreviewSearchMatches( + scope: scope, + searchCorpus: commandPaletteSearchCorpus, candidateCommandIDs: candidateCommandIDs, searchCorpusByID: commandPaletteSearchCorpusByID, query: query, @@ -3400,6 +3402,8 @@ struct ContentView: View { } nonisolated private static func commandPalettePreviewSearchMatches( + scope: CommandPaletteListScope, + searchCorpus: [CommandPaletteSearchCorpusEntry], candidateCommandIDs: [String], searchCorpusByID: [String: CommandPaletteSearchCorpusEntry], query: String, @@ -3408,7 +3412,25 @@ struct ContentView: View { historyTimestamp: TimeInterval, resultLimit: Int ) -> [CommandPaletteResolvedSearchMatch] { - guard !candidateCommandIDs.isEmpty, resultLimit > 0 else { + guard resultLimit > 0 else { + return [] + } + + if scope == .commands { + let matches = commandPaletteResolvedSearchMatches( + searchCorpus: searchCorpus, + query: query, + usageHistory: usageHistory, + queryIsEmpty: queryIsEmpty, + historyTimestamp: historyTimestamp + ) + guard matches.count > resultLimit else { + return matches + } + return Array(matches.prefix(resultLimit)) + } + + guard !candidateCommandIDs.isEmpty else { return [] } @@ -3443,6 +3465,8 @@ struct ContentView: View { ) -> [String] { let preparedQuery = CommandPaletteFuzzyMatcher.preparedQuery(query) return commandPalettePreviewSearchMatches( + scope: .commands, + searchCorpus: searchCorpus, candidateCommandIDs: candidateCommandIDs, searchCorpusByID: searchCorpusByID, query: query,