instant ^E
86468aaf
1 file(s) · +20 −16
| 55 | 55 | static Bool topbar = True; |
|
| 56 | 56 | static DC *dc; |
|
| 57 | 57 | static Item *items = NULL; |
|
| 58 | - | static Item *matches, *sel; |
|
| 59 | - | static Item *prev, *curr, *next; |
|
| 58 | + | static Item *matches, *matchend; |
|
| 59 | + | static Item *prev, *curr, *next, *sel; |
|
| 60 | 60 | static Window root, win; |
|
| 61 | 61 | ||
| 62 | 62 | static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; |
|
| 308 | 308 | cursor = len; |
|
| 309 | 309 | break; |
|
| 310 | 310 | } |
|
| 311 | - | while(next) { |
|
| 312 | - | sel = curr = next; |
|
| 311 | + | if(next) { |
|
| 312 | + | curr = matchend; |
|
| 313 | + | calcoffsets(); |
|
| 314 | + | curr = prev; |
|
| 313 | 315 | calcoffsets(); |
|
| 316 | + | while(next && (curr = curr->right)) |
|
| 317 | + | calcoffsets(); |
|
| 314 | 318 | } |
|
| 315 | - | while(sel && sel->right) |
|
| 316 | - | sel = sel->right; |
|
| 319 | + | sel = matchend; |
|
| 317 | 320 | break; |
|
| 318 | 321 | case XK_Escape: |
|
| 319 | 322 | exit(EXIT_FAILURE); |
|
| 381 | 384 | void |
|
| 382 | 385 | match(void) { |
|
| 383 | 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 | 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 | 391 | for(item = items; item && item->text; item++) |
|
| 389 | 392 | if(!fstrncmp(text, item->text, len + 1)) |
|
| 390 | 393 | appenditem(item, &lexact, &exactend); |
|
| 395 | 398 | ||
| 396 | 399 | if(lexact) { |
|
| 397 | 400 | matches = lexact; |
|
| 398 | - | itemend = exactend; |
|
| 401 | + | matchend = exactend; |
|
| 399 | 402 | } |
|
| 400 | 403 | if(lprefix) { |
|
| 401 | - | if(itemend) { |
|
| 402 | - | itemend->right = lprefix; |
|
| 403 | - | lprefix->left = itemend; |
|
| 404 | + | if(matchend) { |
|
| 405 | + | matchend->right = lprefix; |
|
| 406 | + | lprefix->left = matchend; |
|
| 404 | 407 | } |
|
| 405 | 408 | else |
|
| 406 | 409 | matches = lprefix; |
|
| 407 | - | itemend = prefixend; |
|
| 410 | + | matchend = prefixend; |
|
| 408 | 411 | } |
|
| 409 | 412 | if(lsubstr) { |
|
| 410 | - | if(itemend) { |
|
| 411 | - | itemend->right = lsubstr; |
|
| 412 | - | lsubstr->left = itemend; |
|
| 413 | + | if(matchend) { |
|
| 414 | + | matchend->right = lsubstr; |
|
| 415 | + | lsubstr->left = matchend; |
|
| 413 | 416 | } |
|
| 414 | 417 | else |
|
| 415 | 418 | matches = lsubstr; |
|
| 419 | + | matchend = substrend; |
|
| 416 | 420 | } |
|
| 417 | 421 | curr = sel = matches; |
|
| 418 | 422 | calcoffsets(); |
|