instant ^E

This commit is contained in:
Connor Lane Smith 2011-05-14 18:39:27 +01:00
parent be9afce035
commit 86468aafe5

36
dmenu.c
View File

@ -55,8 +55,8 @@ static Atom utf8;
static Bool topbar = True; static Bool topbar = True;
static DC *dc; static DC *dc;
static Item *items = NULL; static Item *items = NULL;
static Item *matches, *sel; static Item *matches, *matchend;
static Item *prev, *curr, *next; static Item *prev, *curr, *next, *sel;
static Window root, win; static Window root, win;
static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
@ -308,12 +308,15 @@ keypress(XKeyEvent *ev) {
cursor = len; cursor = len;
break; break;
} }
while(next) { if(next) {
sel = curr = next; curr = matchend;
calcoffsets();
curr = prev;
calcoffsets();
while(next && (curr = curr->right))
calcoffsets(); calcoffsets();
} }
while(sel && sel->right) sel = matchend;
sel = sel->right;
break; break;
case XK_Escape: case XK_Escape:
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -381,10 +384,10 @@ keypress(XKeyEvent *ev) {
void void
match(void) { match(void) {
size_t len; size_t len;
Item *item, *itemend, *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend; Item *item, *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend;
len = strlen(text); len = strlen(text);
matches = lexact = lprefix = lsubstr = itemend = exactend = prefixend = substrend = NULL; matches = lexact = lprefix = lsubstr = matchend = exactend = prefixend = substrend = NULL;
for(item = items; item && item->text; item++) for(item = items; item && item->text; item++)
if(!fstrncmp(text, item->text, len + 1)) if(!fstrncmp(text, item->text, len + 1))
appenditem(item, &lexact, &exactend); appenditem(item, &lexact, &exactend);
@ -395,24 +398,25 @@ match(void) {
if(lexact) { if(lexact) {
matches = lexact; matches = lexact;
itemend = exactend; matchend = exactend;
} }
if(lprefix) { if(lprefix) {
if(itemend) { if(matchend) {
itemend->right = lprefix; matchend->right = lprefix;
lprefix->left = itemend; lprefix->left = matchend;
} }
else else
matches = lprefix; matches = lprefix;
itemend = prefixend; matchend = prefixend;
} }
if(lsubstr) { if(lsubstr) {
if(itemend) { if(matchend) {
itemend->right = lsubstr; matchend->right = lsubstr;
lsubstr->left = itemend; lsubstr->left = matchend;
} }
else else
matches = lsubstr; matches = lsubstr;
matchend = substrend;
} }
curr = sel = matches; curr = sel = matches;
calcoffsets(); calcoffsets();