diff --git a/TODO b/TODO index e02a040..cc49802 100644 --- a/TODO +++ b/TODO @@ -3,4 +3,3 @@ - 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) - 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) diff --git a/libs/draw.c b/libs/draw.c index 03975d1..a2359c1 100644 --- a/libs/draw.c +++ b/libs/draw.c @@ -1,28 +1,35 @@ void drawhighlights(struct item *item, int x, int y, int maxw) { - int i, indent; - char *highlight; - char c; - - if (!(strlen(item->text) && strlen(text))) - return; + char restorechar, tokens[sizeof text], *highlight, *token; + int indentx, highlightlen; + char *itemtext = item->text; drw_setscheme(drw, scheme[item == sel ? SchemeSelHighlight : SchemeNormHighlight]); - for (i = 0, highlight = item->text; *highlight && text[i];) { - if (!fstrncmp(&text[i], highlight, 1)) { - c = highlight[1]; - highlight[1] = '\0'; + strcpy(tokens, text); - /* get indentation */ - indent = TEXTW(item->text); + for (token = strtok(tokens, " "); token; token = strtok(NULL, " ")) { + highlight = fstrstr(itemtext, token); + while (highlight) { + highlightlen = highlight - itemtext; + restorechar = *highlight; + itemtext[highlightlen] = '\0'; + indentx = TEXTW(itemtext); + itemtext[highlightlen] = restorechar; - /* highlight character */ - drw_text(drw, x + indent - lrpad, y, MIN(maxw - indent, TEXTW(highlight) - lrpad), bh, 0, highlight, 0, pango_highlight ? True : False); - highlight[1] = c; - i++; + restorechar = highlight[strlen(token)]; + highlight[strlen(token)] = '\0'; + + 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++; } } diff --git a/libs/img.c b/libs/img.c index ced71e1..d3465c6 100644 --- a/libs/img.c +++ b/libs/img.c @@ -311,7 +311,7 @@ jumptoindex(unsigned int index) { unsigned int i; sel = curr = matches; calcoffsets(); - for(i = 1; i < index; ++i) { + for (i = 1; i < index; ++i) { if(sel && sel->right && (sel = sel->right) == next) { curr = next; calcoffsets(); @@ -325,15 +325,15 @@ resizetoimageheight(int imageheight) int omh = mh, olines = lines; lines = reallines; - if(lines * bh < imageheight + imagegaps * 2) - lines = (imageheight+imagegaps*2)/bh; + if (lines * bh < imageheight + imagegaps * 2) + lines = (imageheight + imagegaps * 2) / bh; mh = (lines + 1) * bh; - if(mh - bh < imageheight + imagegaps * 2) - mh = imageheight+imagegaps*2+bh; + if (mh - bh < imageheight + imagegaps * 2) + mh = imageheight + imagegaps * 2 + bh; - if(!win || omh == mh) + if (!win || omh == mh) return; XResizeWindow(dpy, win, mw, mh); @@ -342,6 +342,7 @@ resizetoimageheight(int imageheight) if (olines != lines) { struct item *item; unsigned int i = 1; + for (item = matches; item && item != sel; item = item->right) ++i;