From 4f7996b1ea40f497ada1d79ede522bb7870d576a Mon Sep 17 00:00:00 2001 From: Alexander Montag Date: Tue, 1 Oct 2024 01:05:44 +0200 Subject: [PATCH] Fix new filtering approach for TreeSearch --- editor/tree_search.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/editor/tree_search.cpp b/editor/tree_search.cpp index f35d047..785cd10 100644 --- a/editor/tree_search.cpp +++ b/editor/tree_search.cpp @@ -62,6 +62,7 @@ void TreeSearch::_filter_tree(const String &p_search_mask) { Vector item_visibilities; item_visibilities.resize(ordered_tree_items.size()); + item_visibilities.fill(false); // Make all entries visible that have any matching descendents. O(n) for (int i = 0; i < ordered_tree_items.size(); i++) { @@ -74,11 +75,19 @@ void TreeSearch::_filter_tree(const String &p_search_mask) { // Make all descendents of matching entries visible. O(n) * log(|matching_entries|) for (int i = 0; i < ordered_tree_items.size(); i++) { TreeItem *entry = ordered_tree_items[i]; - TreeItem *next_entry = entry->get_next(); - if (!next_entry && i < ordered_tree_items.size() - 1) { - next_entry = ordered_tree_items[i + 1]; - } if (_vector_has_bsearch(matching_entries, entry)) { + // the [next_entry] at the same depth or depth above. + TreeItem *next_entry = entry->get_next(); + + // search above current depth if no [next_entry]. + while (!next_entry && entry) { + entry = entry->get_parent(); + } + if (entry) { + next_entry = entry->get_next(); + } + + // mark visible all successors upto next entry at the same depth or above int j = i; for (; j < ordered_tree_items.size() && ordered_tree_items[j] != next_entry; j++) { item_visibilities.set(j, true); @@ -87,7 +96,7 @@ void TreeSearch::_filter_tree(const String &p_search_mask) { } } - // apply visibility. O(n) + // Apply visibility. O(n) for (int i = 0; i < ordered_tree_items.size(); i++) { if (!item_visibilities[i]) { ordered_tree_items[i]->set_visible(false); @@ -95,7 +104,7 @@ void TreeSearch::_filter_tree(const String &p_search_mask) { } } -// makes all tree items visible. +// Makes all tree items visible. void TreeSearch::_clear_filter() { ERR_FAIL_COND(!tree_reference); Vector items = { tree_reference->get_root() };