Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-09-09 14:44:39 +0300
committerJacques Lucke <jacques@blender.org>2020-09-09 14:44:45 +0300
commit98eb89be5dd08f3b38f34e7881bae37c3b13e8bb (patch)
tree2ad5a040442d326814f5778d1ed7645ae66f6275 /source/blender/editors/interface/interface_template_search_menu.c
parent45bd8fdc2b086e994fa3e907a64e587013112603 (diff)
UI: improve search results by using fuzzy and prefix matching
Blender does string based searching in many different places. This patch updates four of these places to use the new string search api in `BLI_string_search.h`. In the future we probably want to update the other searches as well. Reviewers: Severin, pablovazquez Differential Revision: https://developer.blender.org/D8825
Diffstat (limited to 'source/blender/editors/interface/interface_template_search_menu.c')
-rw-r--r--source/blender/editors/interface/interface_template_search_menu.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/source/blender/editors/interface/interface_template_search_menu.c b/source/blender/editors/interface/interface_template_search_menu.c
index 667dcfd935d..5bde51846a8 100644
--- a/source/blender/editors/interface/interface_template_search_menu.c
+++ b/source/blender/editors/interface/interface_template_search_menu.c
@@ -41,6 +41,7 @@
#include "BLI_math_matrix.h"
#include "BLI_memarena.h"
#include "BLI_string.h"
+#include "BLI_string_search.h"
#include "BLI_string_utils.h"
#include "BLI_utildefines.h"
@@ -993,19 +994,24 @@ static void menu_search_update_fn(const bContext *UNUSED(C),
{
struct MenuSearch_Data *data = arg;
- /* Prepare BLI_string_all_words_matched. */
- const size_t str_len = strlen(str);
- const int words_max = BLI_string_max_possible_word_count(str_len);
- int(*words)[2] = BLI_array_alloca(words, words_max);
- const int words_len = BLI_string_find_split_words(str, str_len, ' ', words, words_max);
+ StringSearch *search = BLI_string_search_new();
- for (struct MenuSearch_Item *item = data->items.first; item; item = item->next) {
- if (BLI_string_all_words_matched(item->drawwstr_full, str, words, words_len)) {
- if (!UI_search_item_add(items, item->drawwstr_full, item, item->icon, item->state, 0)) {
- break;
- }
+ LISTBASE_FOREACH (struct MenuSearch_Item *, item, &data->items) {
+ BLI_string_search_add(search, item->drawwstr_full, item);
+ }
+
+ struct MenuSearch_Item **filtered_items;
+ int filtered_amount = BLI_string_search_query(search, str, (void ***)&filtered_items);
+
+ for (int i = 0; i < filtered_amount; i++) {
+ struct MenuSearch_Item *item = filtered_items[i];
+ if (!UI_search_item_add(items, item->drawwstr_full, item, item->icon, item->state, 0)) {
+ break;
}
}
+
+ MEM_freeN(filtered_items);
+ BLI_string_search_free(search);
}
/** \} */