From 784fc8cfc6586a3ef8a2aa1168ee259f55d4099c Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 11 Dec 2022 14:28:16 +0100 Subject: [PATCH] Search improvements --- Shared/Search/SearchSuggestions.swift | 14 ++------------ Shared/Search/SearchTextField.swift | 4 ++-- Shared/Search/SearchView.swift | 10 ++++++---- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/Shared/Search/SearchSuggestions.swift b/Shared/Search/SearchSuggestions.swift index f885e1d3..407d0d38 100644 --- a/Shared/Search/SearchSuggestions.swift +++ b/Shared/Search/SearchSuggestions.swift @@ -30,16 +30,10 @@ struct SearchSuggestions: View { HStack { Image(systemName: "magnifyingglass") HStack(spacing: 0) { - if suggestion.hasPrefix(state.suggestionsText.lowercased()) { - Text(state.suggestionsText.lowercased()) - .lineLimit(1) - .layoutPriority(2) - .foregroundColor(.secondary) - } - - Text(querySuffix(suggestion)) + Text(suggestion) .lineLimit(1) .layoutPriority(1) + .truncationMode(.head) .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading) .contentShape(Rectangle()) } @@ -90,10 +84,6 @@ struct SearchSuggestions: View { } } - private func querySuffix(_ suggestion: String) -> String { - suggestion.replacingFirstOccurrence(of: state.suggestionsText.lowercased(), with: "") - } - #if os(macOS) private func onHover(_ inside: Bool) { if inside { diff --git a/Shared/Search/SearchTextField.swift b/Shared/Search/SearchTextField.swift index 845e2189..da868e84 100644 --- a/Shared/Search/SearchTextField.swift +++ b/Shared/Search/SearchTextField.swift @@ -33,8 +33,8 @@ struct SearchTextField: View { .textFieldStyle(.plain) #else .textFieldStyle(.roundedBorder) - .padding(.leading, 5) - .padding(.trailing, 10) + .padding(.horizontal, 5) + .padding(.trailing, state.queryText.isEmpty ? 0 : 10) #endif if !state.queryText.isEmpty { diff --git a/Shared/Search/SearchView.swift b/Shared/Search/SearchView.swift index 84962120..d2cdaf95 100644 --- a/Shared/Search/SearchView.swift +++ b/Shared/Search/SearchView.swift @@ -210,11 +210,13 @@ struct SearchView: View { Section { FavoriteButton(item: favoriteItem) } - } label: { - Image(systemName: "chevron.down.circle.fill") - .foregroundColor(.accentColor) - .imageScale(.medium) + HStack { + Image(systemName: "magnifyingglass") + Image(systemName: "chevron.down.circle.fill") + } + .foregroundColor(.accentColor) + .imageScale(.medium) } } #endif