diff --git a/CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift b/CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift index 8cccb01e5..261a4d224 100644 --- a/CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift +++ b/CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift @@ -27,8 +27,7 @@ extension WorkspaceDocument { @Published var searchResult: [SearchResultModel] = [] @Published var searchResultsFileCount: Int = 0 @Published var searchResultsCount: Int = 0 - /// searchQuery stands for the last search query that corresponds to the search results - /// At the time it's only purpose is to show the query if no files could be found + /// Stores the user's input, shown when no files are found, and persists across navigation items. @Published var searchQuery: String = "" @Published var indexStatus: IndexStatus = .none diff --git a/CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorForm.swift b/CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorForm.swift index c1f748b58..f014492ae 100644 --- a/CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorForm.swift +++ b/CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorForm.swift @@ -18,7 +18,6 @@ struct FindNavigatorForm: View { } } - @State private var searchText: String = "" @State private var replaceText: String = "" @State private var includesText: String = "" @State private var excludesText: String = "" @@ -125,7 +124,7 @@ struct FindNavigatorForm: View { .padding(.bottom, -8) PaneTextField( state.selectedMode[1].title, - text: $searchText, + text: $state.searchQuery, axis: .vertical, leadingAccessories: { Image(systemName: "magnifyingglass") @@ -155,9 +154,9 @@ struct FindNavigatorForm: View { hasValue: caseSensitive ) .onSubmit { - if !searchText.isEmpty { + if !state.searchQuery.isEmpty { Task { - await state.search(searchText) + await state.search(state.searchQuery) } } else { // If a user performs a search with an empty string, the search results will be cleared. @@ -255,7 +254,7 @@ struct FindNavigatorForm: View { Button { Task { let startTime = Date() - try? await state.findAndReplace(query: searchText, replacingTerm: replaceText) + try? await state.findAndReplace(query: state.searchQuery, replacingTerm: replaceText) print(Date().timeIntervalSince(startTime)) } } label: { diff --git a/CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorView.swift b/CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorView.swift index 1b956043c..5e8fb370b 100644 --- a/CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorView.swift +++ b/CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorView.swift @@ -89,10 +89,12 @@ struct FindNavigatorView: View { .safeAreaInset(edge: .bottom, spacing: 0) { FindNavigatorToolbarBottom() } - .onReceive(state.objectWillChange) { _ in - self.searchResultCount = state.searchResultsCount - self.foundFilesCount = state.searchResult.count - } + .onReceive(state.$searchResult, perform: { value in + self.foundFilesCount = value.count + }) + .onReceive(state.$searchResultsCount, perform: { value in + self.searchResultCount = value + }) .onReceive(state.$findNavigatorStatus, perform: { value in self.findNavigatorStatus = value })