From 046155572daa1bb0bf6f2d76005ec5002ce733b0 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Fri, 6 Oct 2023 16:16:07 +0200 Subject: [PATCH] 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 --- source/blender/blenlib/intern/string_search.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/source/blender/blenlib/intern/string_search.cc b/source/blender/blenlib/intern/string_search.cc index 073a0ffe92a..c98de52719d 100644 --- a/source/blender/blenlib/intern/string_search.cc +++ b/source/blender/blenlib/intern/string_search.cc @@ -516,10 +516,14 @@ Vector 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); }