[hackers] [dmenu] fix incorrect ordering of match results || Davide Del Zompo

From: <git_AT_suckless.org>
Date: Sun, 4 Oct 2015 14:05:08 +0200 (CEST)

commit acbf35a5e35b6f6a7dd3f8da49a6e5ec5ac075ce
Author: Davide Del Zompo <davide.delzompo_AT_gmail.com>
AuthorDate: Sun Oct 4 14:01:22 2015 +0200
Commit: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
CommitDate: Sun Oct 4 14:03:07 2015 +0200

    fix incorrect ordering of match results
    
    look for exact matches comparing the user input against the item text

diff --git a/dmenu.c b/dmenu.c
index 509e566..c9fb38b 100644
--- a/dmenu.c
+++ b/dmenu.c
_AT_@ -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);
_AT_@ -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]))
_AT_@ -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);
Received on Sun Oct 04 2015 - 14:05:08 CEST

This archive was generated by hypermail 2.3.0 : Sun Oct 04 2015 - 14:12:10 CEST