diff --git a/format.c b/format.c index 7785c9029..8723f2e03 100644 --- a/format.c +++ b/format.c @@ -4525,11 +4525,14 @@ format_build_modifiers(struct format_expand_state *es, const char **s, return (list); } -/* Fuzzy match strings. */ +/* Fuzzy match a single token (no spaces). */ static int -format_fuzzy_match(const char *pattern, const char *text, int icase) +format_fuzzy_match_token(const char *pattern, size_t patternlen, + const char *text, int icase) { - while (*pattern != '\0') { + const char *end = pattern + patternlen; + + while (pattern != end) { if (*text == '\0') return (0); if (icase) { @@ -4544,6 +4547,31 @@ format_fuzzy_match(const char *pattern, const char *text, int icase) return (1); } +/* + * Fuzzy match strings. The pattern is split on spaces into tokens and every + * token must match as a sequence. + */ +static int +format_fuzzy_match(const char *pattern, const char *text, int icase) +{ + const char *start; + size_t len; + + while (*pattern != '\0') { + while (*pattern == ' ') + pattern++; + if (*pattern == '\0') + break; + start = pattern; + while (*pattern != '\0' && *pattern != ' ') + pattern++; + len = pattern - start; + if (!format_fuzzy_match_token(start, len, text, icase)) + return (0); + } + return (1); +} + /* Match against an fnmatch(3) pattern or regular expression. */ static char * format_match(struct format_modifier *fm, const char *pattern, const char *text) diff --git a/tmux.1 b/tmux.1 index 9b40702f2..d93dce675 100644 --- a/tmux.1 +++ b/tmux.1 @@ -6387,7 +6387,8 @@ means the pattern is a regular expression instead of the default pattern, .Ql z means the pattern is a fuzzy match, that is, it matches if its characters -appear in the string in order but not necessarily consecutively, +appear in the string in order but not necessarily consecutively; +the pattern is split on spaces into separate terms which must all match, and .Ql i means to ignore case.