1
0
mirror of https://github.com/Cloudef/bemenu synced 2024-11-23 17:32:11 +01:00

Remove highlight logic from filters, it does not belong there.

Plus it seems dmenu always just highlights first item on filter change.
This commit is contained in:
Jari Vetoniemi 2014-04-12 14:36:12 +03:00
parent 544b1973c4
commit 9e9b671fa3
3 changed files with 12 additions and 21 deletions

@ -79,17 +79,15 @@ fail:
* @param addition This will be 1, if filter is same as previous filter with something appended.
* @param fstrstr Substring function used to match items.
* @param outNmemb unsigned int reference to filtered items outNmemb.
* @param outHighlighted unsigned int reference to new outHighlighted item index.
* @return Pointer to array of bmItem pointers.
*/
bmItem** _bmFilterDmenuFun(bmMenu *menu, char addition, char* (*fstrstr)(const char *a, const char *b), int (*fstrncmp)(const char *a, const char *b, size_t len), unsigned int *outNmemb, unsigned int *outHighlighted)
bmItem** _bmFilterDmenuFun(bmMenu *menu, char addition, char* (*fstrstr)(const char *a, const char *b), int (*fstrncmp)(const char *a, const char *b, size_t len), unsigned int *outNmemb)
{
assert(menu);
assert(fstrstr);
assert(fstrncmp);
assert(outNmemb);
assert(outHighlighted);
*outNmemb = *outHighlighted = 0;
*outNmemb = 0;
unsigned int itemsCount;
bmItem **items;
@ -110,8 +108,6 @@ bmItem** _bmFilterDmenuFun(bmMenu *menu, char addition, char* (*fstrstr)(const c
if (!(buffer = _bmFilterTokenize(menu, &tokv, &tokc)))
goto fail;
bmItem *highlighted = bmMenuGetHighlightedItem(menu);
size_t len = (tokc ? strlen(tokv[0]) : 0);
unsigned int i, f, e;
for (e = f = i = 0; i < itemsCount; ++i) {
@ -126,9 +122,6 @@ bmItem** _bmFilterDmenuFun(bmMenu *menu, char addition, char* (*fstrstr)(const c
continue;
}
if (item == highlighted)
*outHighlighted = f;
if (tokc && item->text && !fstrncmp(tokv[0], item->text, len + 1)) { /* exact matches */
memmove(&filtered[1], filtered, f * sizeof(bmItem*));
filtered[0] = item;
@ -164,12 +157,11 @@ fail:
* @param menu bmMenu instance to filter.
* @param addition This will be 1, if filter is same as previous filter with something appended.
* @param outNmemb unsigned int reference to filtered items outNmemb.
* @param outHighlighted unsigned int reference to new outHighlighted item index.
* @return Pointer to array of bmItem pointers.
*/
bmItem** _bmFilterDmenu(bmMenu *menu, char addition, unsigned int *outNmemb, unsigned int *outHighlighted)
bmItem** _bmFilterDmenu(bmMenu *menu, char addition, unsigned int *outNmemb)
{
return _bmFilterDmenuFun(menu, addition, strstr, strncmp, outNmemb, outHighlighted);
return _bmFilterDmenuFun(menu, addition, strstr, strncmp, outNmemb);
}
/**
@ -178,12 +170,11 @@ bmItem** _bmFilterDmenu(bmMenu *menu, char addition, unsigned int *outNmemb, uns
* @param menu bmMenu instance to filter.
* @param addition This will be 1, if filter is same as previous filter with something appended.
* @param outNmemb unsigned int reference to filtered items outNmemb.
* @param outHighlighted unsigned int reference to new outHighlighted item index.
* @return Pointer to array of bmItem pointers.
*/
bmItem** _bmFilterDmenuCaseInsensitive(bmMenu *menu, char addition, unsigned int *outNmemb, unsigned int *outHighlighted)
bmItem** _bmFilterDmenuCaseInsensitive(bmMenu *menu, char addition, unsigned int *outNmemb)
{
return _bmFilterDmenuFun(menu, addition, _bmStrupstr, _bmStrnupcmp, outNmemb, outHighlighted);
return _bmFilterDmenuFun(menu, addition, _bmStrupstr, _bmStrnupcmp, outNmemb);
}
/* vim: set ts=8 sw=4 tw=0 :*/

@ -141,8 +141,8 @@ int _bmDrawCursesInit(struct _bmRenderApi *api);
int _bmMenuItemIsSelected(const bmMenu *menu, const bmItem *item);
/* filter.c */
bmItem** _bmFilterDmenu(bmMenu *menu, char addition, unsigned int *outNmemb, unsigned int *outHighlighted);
bmItem** _bmFilterDmenuCaseInsensitive(bmMenu *menu, char addition, unsigned int *outNmemb, unsigned int *outHighlighted);
bmItem** _bmFilterDmenu(bmMenu *menu, char addition, unsigned int *outNmemb);
bmItem** _bmFilterDmenuCaseInsensitive(bmMenu *menu, char addition, unsigned int *outNmemb);
/* list.c */
void _bmItemListFreeList(struct _bmItemList *list);

@ -7,7 +7,7 @@
/**
* Filter function map.
*/
static bmItem** (*filterFunc[BM_FILTER_MODE_LAST])(bmMenu *menu, char addition, unsigned int *outNmemb, unsigned int *outHighlighted) = {
static bmItem** (*filterFunc[BM_FILTER_MODE_LAST])(bmMenu *menu, char addition, unsigned int *outNmemb) = {
_bmFilterDmenu, /* BM_FILTER_DMENU */
_bmFilterDmenuCaseInsensitive /* BM_FILTER_DMENU_CASE_INSENSITIVE */
};
@ -482,11 +482,11 @@ void bmMenuFilter(bmMenu *menu)
if (menu->oldFilter && !strcmp(menu->filter, menu->oldFilter))
return;
unsigned int count, selected;
bmItem **filtered = filterFunc[menu->filterMode](menu, addition, &count, &selected);
unsigned int count;
bmItem **filtered = filterFunc[menu->filterMode](menu, addition, &count);
_bmItemListSetItemsNoCopy(&menu->filtered, filtered, count);
menu->index = selected;
menu->index = 0;
if (menu->oldFilter)
free(menu->oldFilter);