Skip to content

Commit

Permalink
filter: fix exact matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Cloudef committed Aug 29, 2023
1 parent 200f545 commit 45fee14
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ filter_dmenu_fun(struct bm_menu *menu, char addition, char* (*fstrstr)(const cha
if (!(buffer = tokenize(menu, &tokv, &tokc)))
goto fail;

const char *filter = menu->filter ? menu->filter : "";
size_t len = (tokc ? strlen(tokv[0]) : 0);
uint32_t i, f, e;
for (e = f = i = 0; i < count; ++i) {
Expand All @@ -127,14 +128,14 @@ filter_dmenu_fun(struct bm_menu *menu, char addition, char* (*fstrstr)(const cha
continue;
}

if (tokc && item->text && !fstrncmp(tokv[0], item->text, len + 1)) { /* exact matches */
if (tokc && item->text && strlen(filter) == strlen(item->text) && !fstrncmp(filter, item->text, strlen(filter))) { /* exact matches */
memmove(&filtered[1], filtered, f * sizeof(struct bm_item*));
filtered[0] = item;
e++; /* where do exact matches end */
} else if (tokc && item->text && !fstrncmp(tokv[0], item->text, len)) { /* prefixes */
memmove(&filtered[e + 1], &filtered[e], (f - e) * sizeof(struct bm_item*));
filtered[e] = item;
e++; /* where do exact matches end */
e++; /* where do prefix matches end */
} else {
filtered[f] = item;
}
Expand Down

0 comments on commit 45fee14

Please sign in to comment.