Fixed tsv bug (noe we complete and match and calculate offsets with item->stext). Also the cleanupo function gave me spooks so I deleted it's scary part

This commit is contained in:
Андреев Григорий 2025-04-02 14:04:50 +03:00
parent 9fbfcdcee2
commit bd0806de08

24
dmenu.c
View File

@ -99,10 +99,10 @@ calcoffsets(void)
n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">")); n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
/* calculate which items will begin the next page and previous page */ /* calculate which items will begin the next page and previous page */
for (i = 0, next = curr; next; next = next->right) for (i = 0, next = curr; next; next = next->right)
if ((i += (lines > 0) ? bh : textw_clamp(next->text, n)) > n) if ((i += (lines > 0) ? bh : textw_clamp(next->stext, n)) > n)
break; break;
for (i = 0, prev = curr; prev && prev->left; prev = prev->left) for (i = 0, prev = curr; prev && prev->left; prev = prev->left)
if ((i += (lines > 0) ? bh : textw_clamp(prev->left->text, n)) > n) if ((i += (lines > 0) ? bh : textw_clamp(prev->left->stext, n)) > n)
break; break;
} }
@ -110,8 +110,8 @@ static int
max_textw(void) max_textw(void)
{ {
int len = 0; int len = 0;
for (struct item *item = items; item && item->text; item++) for (struct item *item = items; item && item->stext; item++)
len = MAX(TEXTW(item->text), len); len = MAX(TEXTW(item->stext), len);
return len; return len;
} }
@ -123,8 +123,8 @@ cleanup(void)
XUngrabKey(dpy, AnyKey, AnyModifier, root); XUngrabKey(dpy, AnyKey, AnyModifier, root);
for (i = 0; i < SchemeLast; i++) for (i = 0; i < SchemeLast; i++)
free(scheme[i]); free(scheme[i]);
for (i = 0; items && items[i].text; ++i) //for (i = 0; items && items[i].stext; ++i)
free(items[i].text); // free(items[i].text);
free(items); free(items);
drw_free(drw); drw_free(drw);
XSync(dpy, False); XSync(dpy, False);
@ -277,16 +277,16 @@ match(void)
matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL; matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL;
textsize = strlen(text) + 1; textsize = strlen(text) + 1;
for (item = items; item && item->text; item++) { for (item = items; item && item->stext; item++) {
for (i = 0; i < tokc; i++) for (i = 0; i < tokc; i++)
if (!fstrstr(item->text, tokv[i])) if (!fstrstr(item->stext, tokv[i]))
break; break;
if (i != tokc) /* not all tokens match */ if (i != tokc) /* not all tokens match */
continue; continue;
/* exact matches go first, then prefixes, then substrings */ /* exact matches go first, then prefixes, then substrings */
if (!tokc || !fstrncmp(text, item->text, textsize)) if (!tokc || !fstrncmp(text, item->stext, textsize))
appenditem(item, &matches, &matchend); appenditem(item, &matches, &matchend);
else if (!fstrncmp(tokv[0], item->text, len)) else if (!fstrncmp(tokv[0], item->stext, len))
appenditem(item, &lprefix, &prefixend); appenditem(item, &lprefix, &prefixend);
else else
appenditem(item, &lsubstr, &substrend); appenditem(item, &lsubstr, &substrend);
@ -593,8 +593,8 @@ insert:
case XK_Tab: case XK_Tab:
if (!sel) if (!sel)
return; return;
cursor = strnlen(sel->text, sizeof text - 1); cursor = strnlen(sel->stext, sizeof text - 1);
memcpy(text, sel->text, cursor); memcpy(text, sel->stext, cursor);
text[cursor] = '\0'; text[cursor] = '\0';
match(); match();
break; break;