diff --git a/core/string/fuzzy_search.cpp b/core/string/fuzzy_search.cpp index 30357c7efd32..2a2420a52bf4 100644 --- a/core/string/fuzzy_search.cpp +++ b/core/string/fuzzy_search.cpp @@ -30,11 +30,10 @@ #include "fuzzy_search.h" -#include "core/string/ustring.h" #include "core/variant/variant.h" -const float cull_factor = 0.1f; -const float cull_cutoff = 30.0f; +constexpr float cull_factor = 0.1f; +constexpr float cull_cutoff = 30.0f; const String boundary_chars = "/\\-_."; bool is_valid_interval(const Vector2i &p_interval) { @@ -201,7 +200,7 @@ void FuzzySearchResult::add_token_match(const FuzzyTokenMatch &p_match) { token_matches.append(p_match); } -void remove_low_scores(Vector &p_results, const float p_cull_score) { +void remove_low_scores(Vector &p_results, float p_cull_score) { // Removes all results with score < p_cull_score in-place. int i = 0; int j = p_results.size() - 1; @@ -266,7 +265,7 @@ void FuzzySearch::sort_and_filter(Vector &p_results) const { void FuzzySearch::set_query(const String &p_query) { tokens.clear(); for (const String &string : p_query.split(" ", false)) { - tokens.append({ (int)tokens.size(), string }); + tokens.append({ static_cast(tokens.size()), string }); } case_sensitive = !p_query.is_lowercase(); diff --git a/core/string/fuzzy_search.h b/core/string/fuzzy_search.h index edbd089cd1d3..19efcbf79045 100644 --- a/core/string/fuzzy_search.h +++ b/core/string/fuzzy_search.h @@ -36,7 +36,7 @@ class FuzzyTokenMatch; struct FuzzySearchToken { - int idx; + int idx = -1; String string; bool try_exact_match(FuzzyTokenMatch &p_match, const String &p_target, int p_offset) const; diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml index 75e7e60afc39..fd36c60e90e9 100644 --- a/doc/classes/EditorSettings.xml +++ b/doc/classes/EditorSettings.xml @@ -724,7 +724,7 @@ If [code]true[/code], results will include files located in the [code]addons[/code] folder. - The number of allowed character misses in a match, if fuzzy matching is enabled. + The number of allowed missed query characters in a match, if fuzzy matching is enabled. For example, with the default value of 2, [code]foobar[/code] would match [code]foobur[/code] and [code]foob[/code] but not [code]foo[/code]. Maximum number of matches to show in dialog. diff --git a/editor/gui/editor_quick_open_dialog.cpp b/editor/gui/editor_quick_open_dialog.cpp index 3d775efad7ea..349ff86b7aa2 100644 --- a/editor/gui/editor_quick_open_dialog.cpp +++ b/editor/gui/editor_quick_open_dialog.cpp @@ -183,52 +183,45 @@ QuickOpenResultContainer::QuickOpenResultContainer() { } { - // Bottom bar - HBoxContainer *bottom_bar = memnew(HBoxContainer); - bottom_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL); - add_child(bottom_bar); - + // Selected filepath file_details_path = memnew(Label); file_details_path->set_h_size_flags(Control::SIZE_EXPAND_FILL); file_details_path->set_horizontal_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_CENTER); file_details_path->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS); - bottom_bar->add_child(file_details_path); + add_child(file_details_path); + } - { - HBoxContainer *hbc = memnew(HBoxContainer); - hbc->add_theme_constant_override("separation", 3); - bottom_bar->add_child(hbc); - - Label *fuzzy_search_label = memnew(Label); - fuzzy_search_label->set_text(TTR("Fuzzy Search")); - hbc->add_child(fuzzy_search_label); - - fuzzy_search_toggle = memnew(CheckButton); - style_button(fuzzy_search_toggle); - fuzzy_search_toggle->set_tooltip_text(TTR("Enable fuzzy matching")); - fuzzy_search_toggle->connect(SceneStringName(toggled), callable_mp(this, &QuickOpenResultContainer::_toggle_fuzzy_search)); - hbc->add_child(fuzzy_search_toggle); - - Label *include_addons_label = memnew(Label); - include_addons_label->set_text(TTR("Addons")); - hbc->add_child(include_addons_label); - - include_addons_toggle = memnew(CheckButton); - style_button(include_addons_toggle); - include_addons_toggle->set_tooltip_text(TTR("Include files from addons")); - include_addons_toggle->connect(SceneStringName(toggled), callable_mp(this, &QuickOpenResultContainer::_toggle_include_addons)); - hbc->add_child(include_addons_toggle); - - VSeparator *vsep = memnew(VSeparator); - vsep->set_v_size_flags(Control::SIZE_SHRINK_CENTER); - vsep->set_custom_minimum_size(Size2i(0, 14 * EDSCALE)); - hbc->add_child(vsep); - - display_mode_toggle = memnew(Button); - style_button(display_mode_toggle); - display_mode_toggle->connect(SceneStringName(pressed), callable_mp(this, &QuickOpenResultContainer::_toggle_display_mode)); - hbc->add_child(display_mode_toggle); - } + { + // Bottom bar + HBoxContainer *bottom_bar = memnew(HBoxContainer); + bottom_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL); + bottom_bar->set_alignment(ALIGNMENT_END); + bottom_bar->add_theme_constant_override("separation", 3); + add_child(bottom_bar); + + fuzzy_search_toggle = memnew(CheckButton); + style_button(fuzzy_search_toggle); + fuzzy_search_toggle->set_text(TTR("Fuzzy Search")); + fuzzy_search_toggle->set_tooltip_text(TTR("Enable fuzzy matching")); + fuzzy_search_toggle->connect(SceneStringName(toggled), callable_mp(this, &QuickOpenResultContainer::_toggle_fuzzy_search)); + bottom_bar->add_child(fuzzy_search_toggle); + + include_addons_toggle = memnew(CheckButton); + style_button(include_addons_toggle); + include_addons_toggle->set_text(TTR("Addons")); + include_addons_toggle->set_tooltip_text(TTR("Include files from addons")); + include_addons_toggle->connect(SceneStringName(toggled), callable_mp(this, &QuickOpenResultContainer::_toggle_include_addons)); + bottom_bar->add_child(include_addons_toggle); + + VSeparator *vsep = memnew(VSeparator); + vsep->set_v_size_flags(Control::SIZE_SHRINK_CENTER); + vsep->set_custom_minimum_size(Size2i(0, 14 * EDSCALE)); + bottom_bar->add_child(vsep); + + display_mode_toggle = memnew(Button); + style_button(display_mode_toggle); + display_mode_toggle->connect(SceneStringName(pressed), callable_mp(this, &QuickOpenResultContainer::_toggle_display_mode)); + bottom_bar->add_child(display_mode_toggle); } }