diff options
author | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2019-06-12 00:53:30 +0200 |
---|---|---|
committer | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2019-06-12 00:53:30 +0200 |
commit | c6a3dddb74cd4572390d11eb153833e21a3443eb (patch) | |
tree | bee1188f899c76f79aab500ebebd93756ca3689b /dmenu.c | |
parent | Added mouse support patch [Patch] (diff) | |
download | dmenu-c6a3dddb74cd4572390d11eb153833e21a3443eb.tar.gz dmenu-c6a3dddb74cd4572390d11eb153833e21a3443eb.tar.bz2 dmenu-c6a3dddb74cd4572390d11eb153833e21a3443eb.zip |
Added tab complete [Patch]
Diffstat (limited to 'dmenu.c')
-rw-r--r-- | dmenu.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/dmenu.c b/dmenu.c index 0e0f94e..e7ce2fd 100644 --- a/dmenu.c +++ b/dmenu.c @@ -228,8 +228,13 @@ match(void) die("cannot realloc %u bytes:", tokn * sizeof *tokv); len = tokc ? strlen(tokv[0]) : 0; - matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL; - textsize = strlen(text) + 1; + if (use_prefix) { + matches = lprefix = matchend = prefixend = NULL; + textsize = strlen(text); + } else { + matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL; + textsize = strlen(text) + 1; + } for (item = items; item && item->text; item++) { for (i = 0; i < tokc; i++) if (!fstrstr(item->text, tokv[i])) @@ -241,7 +246,7 @@ match(void) appenditem(item, &matches, &matchend); else if (!fstrncmp(tokv[0], item->text, len)) appenditem(item, &lprefix, &prefixend); - else + else if (!use_prefix) appenditem(item, &lsubstr, &substrend); } if (lprefix) { @@ -252,7 +257,7 @@ match(void) matches = lprefix; matchend = prefixend; } - if (lsubstr) { + if (!use_prefix && lsubstr) { if (matches) { matchend->right = lsubstr; lsubstr->left = matchend; @@ -309,6 +314,7 @@ keypress(XKeyEvent *ev) { char buf[32]; int len; + struct item * item; KeySym ksym; Status status; @@ -487,12 +493,17 @@ insert: } break; case XK_Tab: - if (!sel) - return; - strncpy(text, sel->text, sizeof text - 1); + if (!matches) break; /* cannot complete no matches */ + strncpy(text, matches->text, sizeof text - 1); text[sizeof text - 1] = '\0'; - cursor = strlen(text); - match(); + len = cursor = strlen(text); /* length of longest common prefix */ + for (item = matches; item && item->text; item = item->right) { + cursor = 0; + while (cursor < len && text[cursor] == item->text[cursor]) + cursor++; + len = cursor; + } + memset(text + len, '\0', strlen(text) - len); break; } |