From 411ff6084bee21e7d90b1e64521f0e5a2eef5c64 Mon Sep 17 00:00:00 2001 From: Karan Sah Date: Fri, 20 Sep 2024 18:30:57 +0530 Subject: [PATCH 1/4] Fix search text disappearance on changing navigation item --- .../FindNavigator/FindNavigatorForm.swift | 9 ++++----- .../FindNavigator/FindNavigatorView.swift | 10 ++++++---- 2 files changed, 10 insertions(+), 9 deletions(-) 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 }) From 7aaeb4a73647ced20d662880af65143ba552b754 Mon Sep 17 00:00:00 2001 From: Karan Sah Date: Fri, 20 Sep 2024 22:32:50 +0530 Subject: [PATCH 2/4] updated SearchState.searchQuery comment --- .../WorkspaceDocument/WorkspaceDocument+SearchState.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift b/CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift index 8cccb01e5..950249c02 100644 --- a/CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift +++ b/CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift @@ -29,6 +29,7 @@ extension WorkspaceDocument { @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 + /// searchQuery is also used to persist the search text present in search navigator while one switches between the navigation items @Published var searchQuery: String = "" @Published var indexStatus: IndexStatus = .none From 2afdc4fcf7f00b38e398f1a8ffea47c16cb8bbb5 Mon Sep 17 00:00:00 2001 From: Karan Sah <58397645+karan0046@users.noreply.github.com> Date: Sat, 21 Sep 2024 09:00:10 +0530 Subject: [PATCH 3/4] fix swift-lint issue --- .../WorkspaceDocument/WorkspaceDocument+SearchState.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift b/CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift index 950249c02..34297c645 100644 --- a/CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift +++ b/CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift @@ -29,7 +29,7 @@ extension WorkspaceDocument { @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 - /// searchQuery is also used to persist the search text present in search navigator while one switches between the navigation items + /// searchQuery persists the search text in the search navigator as users switch between navigation items @Published var searchQuery: String = "" @Published var indexStatus: IndexStatus = .none From 32c5cd924135d656ee3842d95d9c9efce297a749 Mon Sep 17 00:00:00 2001 From: Karan Sah <58397645+karan0046@users.noreply.github.com> Date: Sat, 21 Sep 2024 17:06:59 +0530 Subject: [PATCH 4/4] Update comment based on suggestion Co-authored-by: Tom Ludwig --- .../WorkspaceDocument/WorkspaceDocument+SearchState.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift b/CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift index 34297c645..261a4d224 100644 --- a/CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift +++ b/CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift @@ -27,9 +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 - /// searchQuery persists the search text in the search navigator as users switch between navigation items + /// 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