summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-08-30 08:50:24 +0200
committerGitHub <noreply@github.com>2019-08-30 08:50:24 +0200
commit931f7d0ebf0da9aaee4a7e375ab0226521f231fd (patch)
tree6d80eea8a806f9ea374c4448921b486a8a7091cb /editor
parent5f4afe0e585dd415a5ed9112c5e8a33145ec0629 (diff)
parenta8a293832ea8de13713f0f7936476a9ce70717c8 (diff)
Merge pull request #31754 from aole/node-selection-issue-on-node-create-dialog
Fix selecting recent node in CreateDialog
Diffstat (limited to 'editor')
-rw-r--r--editor/create_dialog.cpp55
1 files changed, 31 insertions, 24 deletions
diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp
index 8a8d52c6f1..d5f0dc01ee 100644
--- a/editor/create_dialog.cpp
+++ b/editor/create_dialog.cpp
@@ -191,34 +191,41 @@ 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 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 (is_subsequence_of_type && !is_selected_equal) {
- if (is_substring_of_type) {
- if (!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 || (current_type_prefered && !selected_type_prefered)) {
+ // if the node name matches exactly as the search, the node should be selected.
+ // this also fixes when the user clicks on recent nodes.
+ if (p_type.to_lower() == search_term) {
+ *to_select = item;
+ } else {
+ 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;
+
+ 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 (is_subsequence_of_type && !is_selected_equal) {
+ if (is_substring_of_type) {
+ if (!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 || (current_type_prefered && !selected_type_prefered)) {
+ *to_select = item;
+ }
+ }
}
}
}