From 8ab97ddbaf0ef17c9fbb56c8458b0cfdd24c9185 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Thu, 20 Jan 2022 23:13:10 +0100 Subject: [PATCH] Fix search closing when entering new query after opening recent --- Model/RecentsModel.swift | 3 ++- Shared/Search/SearchField.swift | 3 ++- Shared/Search/SearchSuggestions.swift | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Model/RecentsModel.swift b/Model/RecentsModel.swift index 3f2a9ddc..6fa19d38 100644 --- a/Model/RecentsModel.swift +++ b/Model/RecentsModel.swift @@ -34,8 +34,9 @@ final class RecentsModel: ObservableObject { } } - func addQuery(_ query: String) { + func addQuery(_ query: String, navigation: NavigationModel? = nil) { if !query.isEmpty { + navigation?.tabSelection = .search add(.init(from: query)) } } diff --git a/Shared/Search/SearchField.swift b/Shared/Search/SearchField.swift index e5127bc4..d342f49c 100644 --- a/Shared/Search/SearchField.swift +++ b/Shared/Search/SearchField.swift @@ -3,6 +3,7 @@ import SwiftUI struct SearchTextField: View { @Environment(\.navigationStyle) private var navigationStyle + @EnvironmentObject private var navigation @EnvironmentObject private var recents @EnvironmentObject private var state @@ -29,7 +30,7 @@ struct SearchTextField: View { #endif TextField("Search...", text: $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 if state.query.query.compare(state.queryText, options: .caseInsensitive) == .orderedSame { diff --git a/Shared/Search/SearchSuggestions.swift b/Shared/Search/SearchSuggestions.swift index 77109e8d..089d8827 100644 --- a/Shared/Search/SearchSuggestions.swift +++ b/Shared/Search/SearchSuggestions.swift @@ -1,6 +1,7 @@ import SwiftUI struct SearchSuggestions: View { + @EnvironmentObject private var navigation @EnvironmentObject private var recents @EnvironmentObject private var state @@ -76,7 +77,7 @@ struct SearchSuggestions: View { state.fieldIsFocused = false } - recents.addQuery(state.queryText) + recents.addQuery(state.queryText, navigation: navigation) } private var visibleSuggestions: [String] {