From 7bff27a5a5b2be8f374055074c2a9f7a99713cd2 Mon Sep 17 00:00:00 2001 From: Kasper Arnklit Frandsen Date: Thu, 10 Apr 2025 14:57:21 +0100 Subject: [PATCH] Add fuzzy search to method filtering --- editor/plugins/script_editor_plugin.cpp | 26 +++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index a47a968997..e1519feabc 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -37,6 +37,7 @@ #include "core/io/resource_loader.h" #include "core/os/keyboard.h" #include "core/os/os.h" +#include "core/string/fuzzy_search.h" #include "core/version.h" #include "editor/code_editor.h" #include "editor/debugger/editor_debugger_node.h" @@ -2013,13 +2014,30 @@ void ScriptEditor::_update_members_overview() { functions.sort(); } - for (int i = 0; i < functions.size(); i++) { - String filter = filter_methods->get_text(); - String name = functions[i].get_slicec(':', 0); - if (filter.is_empty() || filter.is_subsequence_ofn(name)) { + String filter = filter_methods->get_text(); + if (filter.is_empty()) { + for (int i = 0; i < functions.size(); i++) { + String name = functions[i].get_slicec(':', 0); members_overview->add_item(name); members_overview->set_item_metadata(-1, functions[i].get_slicec(':', 1).to_int() - 1); } + } else { + PackedStringArray search_names; + for (int i = 0; i < functions.size(); i++) { + search_names.append(functions[i].get_slicec(':', 0)); + } + + Vector results; + FuzzySearch fuzzy; + fuzzy.set_query(filter, false); + fuzzy.search_all(search_names, results); + + for (const FuzzySearchResult &res : results) { + String name = functions[res.original_index].get_slicec(':', 0); + int line = functions[res.original_index].get_slicec(':', 1).to_int() - 1; + members_overview->add_item(name); + members_overview->set_item_metadata(-1, line); + } } String path = se->get_edited_resource()->get_path();