UI: use recent search for weighting only if the query is short

The idea is that accessing recent searches is mostly only useful when actually
searching for something very recent, which means that it would show up at the
top even if the query is empty or extremely short. If the user is typing a longer
query, it likely means that what is at the top is not what is actually desired, so
it's better to not take recent searches into account anymore.

Pull Request: https://projects.blender.org/blender/blender/pulls/113338
This commit is contained in:
Jacques Lucke
2023-10-06 16:16:07 +02:00
parent fe39456ba5
commit 046155572d

View File

@@ -516,10 +516,14 @@ Vector<void *> StringSearchBase::query_impl(const StringRef query) const
return items_[a].weight > items_[b].weight;
});
}
/* Prefer items that have been selected recently. */
std::stable_sort(indices.begin(), indices.end(), [&](int a, int b) {
return items_[a].recent_time > items_[b].recent_time;
});
/* If the query gets longer, it's less likely that accessing recent items is desired. Better
* always show the best match in this case. */
if (query.size() <= 1) {
/* Prefer items that have been selected recently. */
std::stable_sort(indices.begin(), indices.end(), [&](int a, int b) {
return items_[a].recent_time > items_[b].recent_time;
});
}
}
sorted_result_indices.extend(indices);
}