aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dmenu.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/dmenu.c b/dmenu.c
index 68fc9ff..b6f1ef2 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -55,8 +55,8 @@ static Atom utf8;
55static Bool topbar = True; 55static Bool topbar = True;
56static DC *dc; 56static DC *dc;
57static Item *items = NULL; 57static Item *items = NULL;
58static Item *matches, *sel; 58static Item *matches, *matchend;
59static Item *prev, *curr, *next; 59static Item *prev, *curr, *next, *sel;
60static Window root, win; 60static Window root, win;
61 61
62static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; 62static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
@@ -308,12 +308,15 @@ keypress(XKeyEvent *ev) {
308 cursor = len; 308 cursor = len;
309 break; 309 break;
310 } 310 }
311 while(next) { 311 if(next) {
312 sel = curr = next; 312 curr = matchend;
313 calcoffsets(); 313 calcoffsets();
314 curr = prev;
315 calcoffsets();
316 while(next && (curr = curr->right))
317 calcoffsets();
314 } 318 }
315 while(sel && sel->right) 319 sel = matchend;
316 sel = sel->right;
317 break; 320 break;
318 case XK_Escape: 321 case XK_Escape:
319 exit(EXIT_FAILURE); 322 exit(EXIT_FAILURE);
@@ -381,10 +384,10 @@ keypress(XKeyEvent *ev) {
381void 384void
382match(void) { 385match(void) {
383 size_t len; 386 size_t len;
384 Item *item, *itemend, *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend; 387 Item *item, *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend;
385 388
386 len = strlen(text); 389 len = strlen(text);
387 matches = lexact = lprefix = lsubstr = itemend = exactend = prefixend = substrend = NULL; 390 matches = lexact = lprefix = lsubstr = matchend = exactend = prefixend = substrend = NULL;
388 for(item = items; item && item->text; item++) 391 for(item = items; item && item->text; item++)
389 if(!fstrncmp(text, item->text, len + 1)) 392 if(!fstrncmp(text, item->text, len + 1))
390 appenditem(item, &lexact, &exactend); 393 appenditem(item, &lexact, &exactend);
@@ -395,24 +398,25 @@ match(void) {
395 398
396 if(lexact) { 399 if(lexact) {
397 matches = lexact; 400 matches = lexact;
398 itemend = exactend; 401 matchend = exactend;
399 } 402 }
400 if(lprefix) { 403 if(lprefix) {
401 if(itemend) { 404 if(matchend) {
402 itemend->right = lprefix; 405 matchend->right = lprefix;
403 lprefix->left = itemend; 406 lprefix->left = matchend;
404 } 407 }
405 else 408 else
406 matches = lprefix; 409 matches = lprefix;
407 itemend = prefixend; 410 matchend = prefixend;
408 } 411 }
409 if(lsubstr) { 412 if(lsubstr) {
410 if(itemend) { 413 if(matchend) {
411 itemend->right = lsubstr; 414 matchend->right = lsubstr;
412 lsubstr->left = itemend; 415 lsubstr->left = matchend;
413 } 416 }
414 else 417 else
415 matches = lsubstr; 418 matches = lsubstr;
419 matchend = substrend;
416 } 420 }
417 curr = sel = matches; 421 curr = sel = matches;
418 calcoffsets(); 422 calcoffsets();