mirror of
https://github.com/yattee/yattee.git
synced 2024-12-23 05:53:41 +00:00
Fix search closing when entering new query after opening recent
This commit is contained in:
parent
df72bf99ba
commit
8ab97ddbaf
@ -34,8 +34,9 @@ final class RecentsModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addQuery(_ query: String) {
|
func addQuery(_ query: String, navigation: NavigationModel? = nil) {
|
||||||
if !query.isEmpty {
|
if !query.isEmpty {
|
||||||
|
navigation?.tabSelection = .search
|
||||||
add(.init(from: query))
|
add(.init(from: query))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import SwiftUI
|
|||||||
struct SearchTextField: View {
|
struct SearchTextField: View {
|
||||||
@Environment(\.navigationStyle) private var navigationStyle
|
@Environment(\.navigationStyle) private var navigationStyle
|
||||||
|
|
||||||
|
@EnvironmentObject<NavigationModel> private var navigation
|
||||||
@EnvironmentObject<RecentsModel> private var recents
|
@EnvironmentObject<RecentsModel> private var recents
|
||||||
@EnvironmentObject<SearchModel> private var state
|
@EnvironmentObject<SearchModel> private var state
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ struct SearchTextField: View {
|
|||||||
#endif
|
#endif
|
||||||
TextField("Search...", text: $state.queryText) {
|
TextField("Search...", text: $state.queryText) {
|
||||||
state.changeQuery { query in query.query = state.queryText }
|
state.changeQuery { query in query.query = state.queryText }
|
||||||
recents.addQuery(state.queryText)
|
recents.addQuery(state.queryText, navigation: navigation)
|
||||||
}
|
}
|
||||||
.onChange(of: state.queryText) { _ in
|
.onChange(of: state.queryText) { _ in
|
||||||
if state.query.query.compare(state.queryText, options: .caseInsensitive) == .orderedSame {
|
if state.query.query.compare(state.queryText, options: .caseInsensitive) == .orderedSame {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct SearchSuggestions: View {
|
struct SearchSuggestions: View {
|
||||||
|
@EnvironmentObject<NavigationModel> private var navigation
|
||||||
@EnvironmentObject<RecentsModel> private var recents
|
@EnvironmentObject<RecentsModel> private var recents
|
||||||
@EnvironmentObject<SearchModel> private var state
|
@EnvironmentObject<SearchModel> private var state
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ struct SearchSuggestions: View {
|
|||||||
state.fieldIsFocused = false
|
state.fieldIsFocused = false
|
||||||
}
|
}
|
||||||
|
|
||||||
recents.addQuery(state.queryText)
|
recents.addQuery(state.queryText, navigation: navigation)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var visibleSuggestions: [String] {
|
private var visibleSuggestions: [String] {
|
||||||
|
Loading…
Reference in New Issue
Block a user