Skip to content

Commit 64cb6dc

Browse files
authored
Fix search text disappearance on changing navigation item (#1889)
1 parent b140b5c commit 64cb6dc

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ extension WorkspaceDocument {
2727
@Published var searchResult: [SearchResultModel] = []
2828
@Published var searchResultsFileCount: Int = 0
2929
@Published var searchResultsCount: Int = 0
30-
/// searchQuery stands for the last search query that corresponds to the search results
31-
/// At the time it's only purpose is to show the query if no files could be found
30+
/// Stores the user's input, shown when no files are found, and persists across navigation items.
3231
@Published var searchQuery: String = ""
3332

3433
@Published var indexStatus: IndexStatus = .none

CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorForm.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ struct FindNavigatorForm: View {
1818
}
1919
}
2020

21-
@State private var searchText: String = ""
2221
@State private var replaceText: String = ""
2322
@State private var includesText: String = ""
2423
@State private var excludesText: String = ""
@@ -125,7 +124,7 @@ struct FindNavigatorForm: View {
125124
.padding(.bottom, -8)
126125
PaneTextField(
127126
state.selectedMode[1].title,
128-
text: $searchText,
127+
text: $state.searchQuery,
129128
axis: .vertical,
130129
leadingAccessories: {
131130
Image(systemName: "magnifyingglass")
@@ -155,9 +154,9 @@ struct FindNavigatorForm: View {
155154
hasValue: caseSensitive
156155
)
157156
.onSubmit {
158-
if !searchText.isEmpty {
157+
if !state.searchQuery.isEmpty {
159158
Task {
160-
await state.search(searchText)
159+
await state.search(state.searchQuery)
161160
}
162161
} else {
163162
// If a user performs a search with an empty string, the search results will be cleared.
@@ -255,7 +254,7 @@ struct FindNavigatorForm: View {
255254
Button {
256255
Task {
257256
let startTime = Date()
258-
try? await state.findAndReplace(query: searchText, replacingTerm: replaceText)
257+
try? await state.findAndReplace(query: state.searchQuery, replacingTerm: replaceText)
259258
print(Date().timeIntervalSince(startTime))
260259
}
261260
} label: {

CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorView.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,12 @@ struct FindNavigatorView: View {
8989
.safeAreaInset(edge: .bottom, spacing: 0) {
9090
FindNavigatorToolbarBottom()
9191
}
92-
.onReceive(state.objectWillChange) { _ in
93-
self.searchResultCount = state.searchResultsCount
94-
self.foundFilesCount = state.searchResult.count
95-
}
92+
.onReceive(state.$searchResult, perform: { value in
93+
self.foundFilesCount = value.count
94+
})
95+
.onReceive(state.$searchResultsCount, perform: { value in
96+
self.searchResultCount = value
97+
})
9698
.onReceive(state.$findNavigatorStatus, perform: { value in
9799
self.findNavigatorStatus = value
98100
})

0 commit comments

Comments
 (0)