]> git.armaanb.net Git - dmenu.git/commitdiff
fix incorrect ordering of match results
authorDavide Del Zompo <davide.delzompo@gmail.com>
Sun, 4 Oct 2015 12:01:22 +0000 (14:01 +0200)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Sun, 4 Oct 2015 12:03:07 +0000 (14:03 +0200)
look for exact matches comparing the user input against the item text

dmenu.c

diff --git a/dmenu.c b/dmenu.c
index 509e566203d4441e0f92f2cc87f1aa0ac9adc4f4..c9fb38bde2e487574f8367d33a6a18979bfdac9c 100644 (file)
--- a/dmenu.c
+++ b/dmenu.c
@@ -208,7 +208,7 @@ match(void)
 
        char buf[sizeof text], *s;
        int i, tokc = 0;
-       size_t len;
+       size_t len, textsize;
        struct item *item, *lprefix, *lsubstr, *prefixend, *substrend;
 
        strcpy(buf, text);
@@ -219,6 +219,7 @@ match(void)
        len = tokc ? strlen(tokv[0]) : 0;
 
        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]))
@@ -226,7 +227,7 @@ match(void)
                if (i != tokc) /* not all tokens match */
                        continue;
                /* exact matches go first, then prefixes, then substrings */
-               if (!tokc || !fstrncmp(tokv[0], item->text, len + 1))
+               if (!tokc || !fstrncmp(text, item->text, textsize))
                        appenditem(item, &matches, &matchend);
                else if (!fstrncmp(tokv[0], item->text, len))
                        appenditem(item, &lprefix, &prefixend);