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(">"));
/* calculate which items will begin the next page and previous page */
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;
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;
}
@ -110,8 +110,8 @@ static int
max_textw(void)
{
int len = 0;
for (struct item *item = items; item && item->text; item++)
len = MAX(TEXTW(item->text), len);
for (struct item *item = items; item && item->stext; item++)
len = MAX(TEXTW(item->stext), len);
return len;
}
@ -123,8 +123,8 @@ cleanup(void)
XUngrabKey(dpy, AnyKey, AnyModifier, root);
for (i = 0; i < SchemeLast; i++)
free(scheme[i]);
for (i = 0; items && items[i].text; ++i)
free(items[i].text);
//for (i = 0; items && items[i].stext; ++i)
// free(items[i].text);
free(items);
drw_free(drw);
XSync(dpy, False);
@ -277,16 +277,16 @@ match(void)
matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL;
textsize = strlen(text) + 1;
for (item = items; item && item->text; item++) {
for (item = items; item && item->stext; item++) {
for (i = 0; i < tokc; i++)
if (!fstrstr(item->text, tokv[i]))
if (!fstrstr(item->stext, tokv[i]))
break;
if (i != tokc) /* not all tokens match */
continue;
/* 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);
else if (!fstrncmp(tokv[0], item->text, len))
else if (!fstrncmp(tokv[0], item->stext, len))
appenditem(item, &lprefix, &prefixend);
else
appenditem(item, &lsubstr, &substrend);
@ -593,8 +593,8 @@ insert:
case XK_Tab:
if (!sel)
return;
cursor = strnlen(sel->text, sizeof text - 1);
memcpy(text, sel->text, cursor);
cursor = strnlen(sel->stext, sizeof text - 1);
memcpy(text, sel->stext, cursor);
text[cursor] = '\0';
match();
break;