diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-07-01 12:03:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-01 12:03:16 +0200 |
commit | e285114e0ce6534add2d74232ee61f6a4b2f1f81 (patch) | |
tree | 5a08bef6833ac326b7a9797d9703a7283eec344a /editor | |
parent | ed2f753fdbacf7d7b4a8f0408dddb19ae2a6707f (diff) | |
parent | 80a0d1701bcaab3801d42707c40b7951b1d4bed1 (diff) |
Merge pull request #30072 from mbrlabs/node-search-fix
Better pre-selection of search result node in "Create New Node" dialog.
Diffstat (limited to 'editor')
-rw-r--r-- | editor/create_dialog.cpp | 55 | ||||
-rw-r--r-- | editor/create_dialog.h | 1 |
2 files changed, 39 insertions, 17 deletions
diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index e84602b29f..9a152d663a 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -191,24 +191,36 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p item->set_custom_color(0, get_color("disabled_font_color", "Editor")); item->set_selectable(0, false); } else if (!(*to_select && (*to_select)->get_text(0) == search_box->get_text())) { - bool is_search_subsequence = search_box->get_text().is_subsequence_ofi(p_type); - String to_select_type = *to_select ? (*to_select)->get_text(0) : ""; - to_select_type = to_select_type.split(" ")[0]; - bool current_item_is_preferred; - if (cpp_type) { - String cpp_to_select_type = to_select_type; - if (ScriptServer::is_global_class(to_select_type)) - cpp_to_select_type = ScriptServer::get_global_class_native_base(to_select_type); - current_item_is_preferred = ClassDB::is_parent_class(p_type, preferred_search_result_type) && !ClassDB::is_parent_class(cpp_to_select_type, preferred_search_result_type); - } else { - current_item_is_preferred = ed.script_class_is_parent(p_type, preferred_search_result_type) && !ed.script_class_is_parent(to_select_type, preferred_search_result_type) && search_box->get_text() != to_select_type; - } - if (search_box->get_text() == p_type || (*to_select && p_type.length() < (*to_select)->get_text(0).length())) { - current_item_is_preferred = true; + bool current_type_prefered = _is_type_prefered(p_type); + bool selected_type_prefered = *to_select ? _is_type_prefered((*to_select)->get_text(0).split(" ")[0]) : false; + + String search_term = search_box->get_text().to_lower(); + bool is_subsequence_of_type = search_box->get_text().is_subsequence_ofi(p_type); + bool is_substring_of_type = p_type.to_lower().find(search_term) >= 0; + bool is_substring_of_selected = false; + bool is_subsequence_of_selected = false; + bool is_selected_equal = false; + + if (*to_select) { + String name = (*to_select)->get_text(0).split(" ")[0].to_lower(); + is_substring_of_selected = name.find(search_term) >= 0; + is_subsequence_of_selected = search_term.is_subsequence_of(name); + is_selected_equal = name == search_term; } - if (((!*to_select || current_item_is_preferred) && is_search_subsequence)) { - *to_select = item; + if (is_subsequence_of_type && !is_selected_equal) { + if (is_substring_of_type) { + if (!is_substring_of_selected || (is_substring_of_selected && (current_type_prefered && !selected_type_prefered))) { + *to_select = item; + } + } else { + // substring results weigh more than subsequences, so let's make sure we don't override them + if (!is_substring_of_selected) { + if (!is_subsequence_of_selected || (is_subsequence_of_selected && (current_type_prefered && !selected_type_prefered))) { + *to_select = item; + } + } + } } } @@ -232,6 +244,16 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p p_types[p_type] = item; } +bool CreateDialog::_is_type_prefered(const String &type) { + bool cpp_type = ClassDB::class_exists(type); + EditorData &ed = EditorNode::get_editor_data(); + + if (cpp_type) { + return ClassDB::is_parent_class(type, preferred_search_result_type); + } + return ed.script_class_is_parent(type, preferred_search_result_type); +} + bool CreateDialog::_is_class_disabled_by_feature_profile(const StringName &p_class) { Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile(); @@ -275,7 +297,6 @@ void CreateDialog::select_type(const String &p_type) { } void CreateDialog::_update_search() { - search_options->clear(); favorite->set_disabled(true); diff --git a/editor/create_dialog.h b/editor/create_dialog.h index 0eddbc3ceb..f6c3b57589 100644 --- a/editor/create_dialog.h +++ b/editor/create_dialog.h @@ -90,6 +90,7 @@ class CreateDialog : public ConfirmationDialog { void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); bool _is_class_disabled_by_feature_profile(const StringName &p_class); + bool _is_type_prefered(const String &type); protected: void _notification(int p_what); |