Reset palette results on scope change
This commit is contained in:
parent
6edcaa220b
commit
6c9e4d14e5
1 changed files with 26 additions and 4 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue