fix: last character not highlighted

This commit is contained in:
speedie 2023-03-08 19:20:18 +01:00
parent 03a245720e
commit 6450a36f13
3 changed files with 31 additions and 24 deletions

1
TODO
View file

@ -3,4 +3,3 @@
- Mouse bind array (mouse.h) - Mouse bind array (mouse.h)
- Remove SGR sequences from width when item text is drawn, currently the width of the item before SGR sequences are used, resulting in some ugly behavior for the selected item (drawitem function libs/draw.c) - Remove SGR sequences from width when item text is drawn, currently the width of the item before SGR sequences are used, resulting in some ugly behavior for the selected item (drawitem function libs/draw.c)
- Add configuration file using (probably) libconfig - Add configuration file using (probably) libconfig
- Fix highlighting for last character in a match, sometimes it will not be highlighted and I am not yet entirely sure (drawhighlight function libs/draw.c)

View file

@ -1,28 +1,35 @@
void void
drawhighlights(struct item *item, int x, int y, int maxw) drawhighlights(struct item *item, int x, int y, int maxw)
{ {
int i, indent; char restorechar, tokens[sizeof text], *highlight, *token;
char *highlight; int indentx, highlightlen;
char c; char *itemtext = item->text;
if (!(strlen(item->text) && strlen(text)))
return;
drw_setscheme(drw, scheme[item == sel ? SchemeSelHighlight : SchemeNormHighlight]); drw_setscheme(drw, scheme[item == sel ? SchemeSelHighlight : SchemeNormHighlight]);
for (i = 0, highlight = item->text; *highlight && text[i];) { strcpy(tokens, text);
if (!fstrncmp(&text[i], highlight, 1)) {
c = highlight[1];
highlight[1] = '\0';
/* get indentation */ for (token = strtok(tokens, " "); token; token = strtok(NULL, " ")) {
indent = TEXTW(item->text); highlight = fstrstr(itemtext, token);
while (highlight) {
highlightlen = highlight - itemtext;
restorechar = *highlight;
itemtext[highlightlen] = '\0';
indentx = TEXTW(itemtext);
itemtext[highlightlen] = restorechar;
/* highlight character */ restorechar = highlight[strlen(token)];
drw_text(drw, x + indent - lrpad, y, MIN(maxw - indent, TEXTW(highlight) - lrpad), bh, 0, highlight, 0, pango_highlight ? True : False); highlight[strlen(token)] = '\0';
highlight[1] = c;
i++; if (indentx - (lrpad / 2) - 1 < maxw)
drw_text(drw, x + indentx - (lrpad / 2) - 1, y, MIN(maxw - indentx, TEXTW(highlight) - lrpad), bh, 0, highlight, 0, pango_highlight ? True : False);
highlight[strlen(token)] = restorechar;
if (strlen(highlight) - strlen(token) < strlen(token))
break;
highlight = fstrstr(highlight + strlen(token), token);
} }
highlight++;
} }
} }

View file

@ -342,6 +342,7 @@ resizetoimageheight(int imageheight)
if (olines != lines) { if (olines != lines) {
struct item *item; struct item *item;
unsigned int i = 1; unsigned int i = 1;
for (item = matches; item && item != sel; item = item->right) for (item = matches; item && item != sel; item = item->right)
++i; ++i;