Browse Source

Merge pull request #105996 from a-johnston/fuzzy_search_case_fix

Only update case sensitive fuzzy searching within `set_query`
Thaddeus Crews 3 months ago
parent
commit
c2fde491b7
2 changed files with 12 additions and 4 deletions
  1. 10 3
      core/string/fuzzy_search.cpp
  2. 2 1
      core/string/fuzzy_search.h

+ 10 - 3
core/string/fuzzy_search.cpp

@@ -265,13 +265,20 @@ void FuzzySearch::sort_and_filter(Vector<FuzzySearchResult> &p_results) const {
 }
 
 void FuzzySearch::set_query(const String &p_query) {
+	set_query(p_query, !p_query.is_lowercase());
+}
+
+void FuzzySearch::set_query(const String &p_query, bool p_case_sensitive) {
 	tokens.clear();
+	case_sensitive = p_case_sensitive;
+
 	for (const String &string : p_query.split(" ", false)) {
-		tokens.append({ static_cast<int>(tokens.size()), string });
+		tokens.append({
+				static_cast<int>(tokens.size()),
+				p_case_sensitive ? string : string.to_lower(),
+		});
 	}
 
-	case_sensitive = !p_query.is_lowercase();
-
 	struct TokenComparator {
 		bool operator()(const FuzzySearchToken &A, const FuzzySearchToken &B) const {
 			if (A.string.length() == B.string.length()) {

+ 2 - 1
core/string/fuzzy_search.h

@@ -84,16 +84,17 @@ public:
 class FuzzySearch {
 	Vector<FuzzySearchToken> tokens;
 
+	bool case_sensitive = false;
 	void sort_and_filter(Vector<FuzzySearchResult> &p_results) const;
 
 public:
 	int start_offset = 0;
-	bool case_sensitive = false;
 	int max_results = 100;
 	int max_misses = 2;
 	bool allow_subsequences = true;
 
 	void set_query(const String &p_query);
+	void set_query(const String &p_query, bool p_case_sensitive);
 	bool search(const String &p_target, FuzzySearchResult &p_result) const;
 	void search_all(const PackedStringArray &p_targets, Vector<FuzzySearchResult> &p_results) const;
 };