Fix new filtering approach for TreeSearch
This commit is contained in:
parent
74cf9855a7
commit
4f7996b1ea
|
@ -62,6 +62,7 @@ void TreeSearch::_filter_tree(const String &p_search_mask) {
|
||||||
|
|
||||||
Vector<bool> item_visibilities;
|
Vector<bool> item_visibilities;
|
||||||
item_visibilities.resize(ordered_tree_items.size());
|
item_visibilities.resize(ordered_tree_items.size());
|
||||||
|
item_visibilities.fill(false);
|
||||||
|
|
||||||
// Make all entries visible that have any matching descendents. O(n)
|
// Make all entries visible that have any matching descendents. O(n)
|
||||||
for (int i = 0; i < ordered_tree_items.size(); i++) {
|
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|)
|
// Make all descendents of matching entries visible. O(n) * log(|matching_entries|)
|
||||||
for (int i = 0; i < ordered_tree_items.size(); i++) {
|
for (int i = 0; i < ordered_tree_items.size(); i++) {
|
||||||
TreeItem *entry = ordered_tree_items[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)) {
|
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;
|
int j = i;
|
||||||
for (; j < ordered_tree_items.size() && ordered_tree_items[j] != next_entry; j++) {
|
for (; j < ordered_tree_items.size() && ordered_tree_items[j] != next_entry; j++) {
|
||||||
item_visibilities.set(j, true);
|
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++) {
|
for (int i = 0; i < ordered_tree_items.size(); i++) {
|
||||||
if (!item_visibilities[i]) {
|
if (!item_visibilities[i]) {
|
||||||
ordered_tree_items[i]->set_visible(false);
|
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() {
|
void TreeSearch::_clear_filter() {
|
||||||
ERR_FAIL_COND(!tree_reference);
|
ERR_FAIL_COND(!tree_reference);
|
||||||
Vector<TreeItem *> items = { tree_reference->get_root() };
|
Vector<TreeItem *> items = { tree_reference->get_root() };
|
||||||
|
|
Loading…
Reference in New Issue