Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search text disappearance on changing navigation item #1889

Merged
merged 4 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 persists the search text in the search navigator as users switch between navigation items
karan0046 marked this conversation as resolved.
Show resolved Hide resolved
@Published var searchQuery: String = ""

@Published var indexStatus: IndexStatus = .none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down