Merge pull request #12640 from poke1024/createnode-ui
In Create New Node, always select and show best (shortest) match
This commit is contained in:
commit
a0ac0804ca
3 changed files with 25 additions and 0 deletions
|
@ -171,6 +171,9 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p
|
|||
bool is_search_subsequence = search_box->get_text().is_subsequence_ofi(p_type);
|
||||
String to_select_type = *to_select ? (*to_select)->get_text(0) : "";
|
||||
bool current_item_is_preffered = ClassDB::is_parent_class(p_type, preferred_search_result_type) && !ClassDB::is_parent_class(to_select_type, preferred_search_result_type);
|
||||
if (*to_select && p_type.length() < (*to_select)->get_text(0).length()) {
|
||||
current_item_is_preffered = true;
|
||||
}
|
||||
|
||||
if (((!*to_select || current_item_is_preffered) && is_search_subsequence) || search_box->get_text() == p_type) {
|
||||
*to_select = item;
|
||||
|
@ -290,6 +293,7 @@ void CreateDialog::_update_search() {
|
|||
|
||||
if (to_select) {
|
||||
to_select->select(0);
|
||||
search_options->scroll_to_item(to_select);
|
||||
favorite->set_disabled(false);
|
||||
favorite->set_pressed(favorite_list.find(to_select->get_text(0)) != -1);
|
||||
}
|
||||
|
|
|
@ -3332,6 +3332,26 @@ Point2 Tree::get_scroll() const {
|
|||
return ofs;
|
||||
}
|
||||
|
||||
void Tree::scroll_to_item(TreeItem *p_item) {
|
||||
|
||||
if (!is_visible_in_tree()) {
|
||||
|
||||
// hack to work around crash in get_item_rect() if Tree is not in tree.
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure the scrollbar min and max are up to date with latest changes.
|
||||
update_scrollbars();
|
||||
|
||||
const Rect2 r = get_item_rect(p_item);
|
||||
|
||||
if (r.position.y < v_scroll->get_value()) {
|
||||
v_scroll->set_value(r.position.y);
|
||||
} else if (r.position.y + r.size.y + 2 * cache.vseparation > v_scroll->get_value() + get_size().y) {
|
||||
v_scroll->set_value(r.position.y + r.size.y + 2 * cache.vseparation - get_size().y);
|
||||
}
|
||||
}
|
||||
|
||||
TreeItem *Tree::_search_item_text(TreeItem *p_at, const String &p_find, int *r_col, bool p_selectable, bool p_backwards) {
|
||||
|
||||
while (p_at) {
|
||||
|
|
|
@ -570,6 +570,7 @@ public:
|
|||
TreeItem *search_item_text(const String &p_find, int *r_col = NULL, bool p_selectable = false);
|
||||
|
||||
Point2 get_scroll() const;
|
||||
void scroll_to_item(TreeItem *p_item);
|
||||
|
||||
void set_cursor_can_exit_tree(bool p_enable);
|
||||
bool can_cursor_exit_tree() const;
|
||||
|
|
Loading…
Reference in a new issue