diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-03-24 15:28:46 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-03-24 15:30:51 +0300 |
commit | 8249046b82f7a7a79eac42f3870349604eeb2711 (patch) | |
tree | 4cf28d9664b2ce18b6346fbd34cf4afab2bd1418 /source/blender/editors/interface/interface_templates.c | |
parent | 70fcecc1f788772ac0ecdbd647583afe995423bb (diff) |
UI: search operator's by word prefix
Would match middle of words which wasn't very useful in most cases.
Diffstat (limited to 'source/blender/editors/interface/interface_templates.c')
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index e48b09d1858..9f98c0dea30 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -25,6 +25,7 @@ */ +#include <ctype.h> #include <stdlib.h> #include <stddef.h> #include <string.h> @@ -3271,6 +3272,22 @@ static void operator_call_cb(bContext *C, void *UNUSED(arg1), void *arg2) WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, NULL); } +static bool has_word_prefix(const char *haystack, const char *needle, size_t needle_len) +{ + const char *match = BLI_strncasestr(haystack, needle, needle_len); + if (match) { + if ((match == haystack) || (*(match - 1) == ' ') || ispunct(*(match - 1))) { + return true; + } + else { + return has_word_prefix(match + 1, needle, needle_len); + } + } + else { + return false; + } +} + static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char *str, uiSearchItems *items) { GHashIterator iter; @@ -3290,7 +3307,7 @@ static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char /* match name against all search words */ for (index = 0; index < words_len; index++) { - if (!BLI_strncasestr(ot_ui_name, str + words[index][0], words[index][1])) { + if (!has_word_prefix(ot_ui_name, str + words[index][0], words[index][1])) { break; } } |