aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavide Del Zompo <davide.delzompo@gmail.com>2015-10-04 14:01:22 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2015-10-04 14:03:07 +0200
commitacbf35a5e35b6f6a7dd3f8da49a6e5ec5ac075ce (patch)
treee6a967b167a8bd0ffdd7a373034d04239b7e32a9
parent240a7810e492ec01075614729a1a1c45ef9f7af2 (diff)
fix incorrect ordering of match results
look for exact matches comparing the user input against the item text
-rw-r--r--dmenu.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/dmenu.c b/dmenu.c
index 509e566..c9fb38b 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -208,7 +208,7 @@ match(void)
208 208
209 char buf[sizeof text], *s; 209 char buf[sizeof text], *s;
210 int i, tokc = 0; 210 int i, tokc = 0;
211 size_t len; 211 size_t len, textsize;
212 struct item *item, *lprefix, *lsubstr, *prefixend, *substrend; 212 struct item *item, *lprefix, *lsubstr, *prefixend, *substrend;
213 213
214 strcpy(buf, text); 214 strcpy(buf, text);
@@ -219,6 +219,7 @@ match(void)
219 len = tokc ? strlen(tokv[0]) : 0; 219 len = tokc ? strlen(tokv[0]) : 0;
220 220
221 matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL; 221 matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL;
222 textsize = strlen(text) + 1;
222 for (item = items; item && item->text; item++) { 223 for (item = items; item && item->text; item++) {
223 for (i = 0; i < tokc; i++) 224 for (i = 0; i < tokc; i++)
224 if (!fstrstr(item->text, tokv[i])) 225 if (!fstrstr(item->text, tokv[i]))
@@ -226,7 +227,7 @@ match(void)
226 if (i != tokc) /* not all tokens match */ 227 if (i != tokc) /* not all tokens match */
227 continue; 228 continue;
228 /* exact matches go first, then prefixes, then substrings */ 229 /* exact matches go first, then prefixes, then substrings */
229 if (!tokc || !fstrncmp(tokv[0], item->text, len + 1)) 230 if (!tokc || !fstrncmp(text, item->text, textsize))
230 appenditem(item, &matches, &matchend); 231 appenditem(item, &matches, &matchend);
231 else if (!fstrncmp(tokv[0], item->text, len)) 232 else if (!fstrncmp(tokv[0], item->text, len))
232 appenditem(item, &lprefix, &prefixend); 233 appenditem(item, &lprefix, &prefixend);