diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-02-09 10:43:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-09 10:43:21 +0100 |
commit | df9c98e107b19fc50bc5ae9f7ed624d693c0fb32 (patch) | |
tree | 96d04bb7beec118027cdf3eebee27e8343fe1f20 /editor/scene_tree_editor.cpp | |
parent | e9bc984bef146a73acd3060f634018a15df1b72d (diff) | |
parent | ef062b1c37b22ad23bc243756a2a40958e8d3554 (diff) |
Merge pull request #45812 from RandomShaper/keep_selected_visible
Keep selected node visible after filter change
Diffstat (limited to 'editor/scene_tree_editor.cpp')
-rw-r--r-- | editor/scene_tree_editor.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp index b8475656ee..ce44a4bca1 100644 --- a/editor/scene_tree_editor.cpp +++ b/editor/scene_tree_editor.cpp @@ -156,7 +156,7 @@ void SceneTreeEditor::_toggle_visible(Node *p_node) { } } -bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { +bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll_to_selected) { if (!p_node) { return false; } @@ -391,15 +391,19 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { } } + bool scroll = false; + if (editor_selection) { if (editor_selection->is_selected(p_node)) { item->select(0); + scroll = p_scroll_to_selected; } } if (selected == p_node) { if (!editor_selection) { item->select(0); + scroll = p_scroll_to_selected; } item->set_as_cursor(0); } @@ -407,7 +411,7 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { bool keep = (filter.is_subsequence_ofi(String(p_node->get_name()))); for (int i = 0; i < p_node->get_child_count(); i++) { - bool child_keep = _add_nodes(p_node->get_child(i), item); + bool child_keep = _add_nodes(p_node->get_child(i), item, p_scroll_to_selected); keep = keep || child_keep; } @@ -438,6 +442,9 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { memdelete(item); return false; } else { + if (scroll) { + tree->scroll_to_item(item); + } return true; } } @@ -525,7 +532,7 @@ void SceneTreeEditor::_node_renamed(Node *p_node) { } } -void SceneTreeEditor::_update_tree() { +void SceneTreeEditor::_update_tree(bool p_scroll_to_selected) { if (!is_inside_tree()) { tree_dirty = false; return; @@ -534,7 +541,7 @@ void SceneTreeEditor::_update_tree() { updating_tree = true; tree->clear(); if (get_scene_node()) { - _add_nodes(get_scene_node(), nullptr); + _add_nodes(get_scene_node(), nullptr, p_scroll_to_selected); last_hash = hash_djb2_one_64(0); _compute_hash(get_scene_node(), last_hash); } @@ -817,7 +824,7 @@ void SceneTreeEditor::set_marked(Node *p_marked, bool p_selectable, bool p_child void SceneTreeEditor::set_filter(const String &p_filter) { filter = p_filter; - _update_tree(); + _update_tree(true); } String SceneTreeEditor::get_filter() const { |