Reset palette results on scope change

This commit is contained in:
Lawrence Chen 2026-03-13 16:06:40 -07:00
parent 6edcaa220b
commit 6c9e4d14e5
No known key found for this signature in database

View file

@ -3208,12 +3208,22 @@ struct ContentView: View {
updateCommandPaletteScrollTarget(resultCount: commandPaletteVisibleResults.count, animated: false)
resetCommandPaletteSearchFocus()
}
.onChange(of: commandPaletteQuery) { _ in
.onChange(of: commandPaletteQuery) { oldValue, newValue in
commandPaletteSelectedResultIndex = 0
commandPaletteSelectionAnchorCommandID = nil
commandPaletteHoveredResultIndex = nil
commandPaletteScrollTargetIndex = nil
commandPaletteScrollTargetAnchor = nil
if Self.commandPaletteShouldResetVisibleResultsForQueryTransition(
oldQuery: oldValue,
newQuery: newValue,
hasVisibleResults: commandPaletteVisibleResultsScope != nil
) {
cachedCommandPaletteResults = []
commandPaletteVisibleResults = []
commandPaletteVisibleResultsScope = nil
commandPaletteVisibleResultsFingerprint = nil
}
scheduleCommandPaletteResultsRefresh()
updateCommandPaletteScrollTarget(resultCount: commandPaletteVisibleResults.count, animated: false)
syncCommandPaletteDebugStateForObservedWindow()
@ -3346,14 +3356,26 @@ struct ContentView: View {
}
private var commandPaletteListScope: CommandPaletteListScope {
if commandPaletteQuery.hasPrefix(Self.commandPaletteCommandsPrefix) {
Self.commandPaletteListScope(for: commandPaletteQuery)
}
private var commandPaletteCurrentSearchFingerprint: Int {
commandPaletteEntriesFingerprint(for: commandPaletteListScope)
}
private static func commandPaletteListScope(for query: String) -> CommandPaletteListScope {
if query.hasPrefix(Self.commandPaletteCommandsPrefix) {
return .commands
}
return .switcher
}
private var commandPaletteCurrentSearchFingerprint: Int {
commandPaletteEntriesFingerprint(for: commandPaletteListScope)
static func commandPaletteShouldResetVisibleResultsForQueryTransition(
oldQuery: String,
newQuery: String,
hasVisibleResults: Bool
) -> Bool {
hasVisibleResults && commandPaletteListScope(for: oldQuery) != commandPaletteListScope(for: newQuery)
}
private var commandPaletteSwitcherIncludesSurfaceEntries: Bool {