Apply word wrapping to tabs before setting align

This fixes long URLs right after the initial \t being wrapped and line
counted incorrectly.
master
C. McEnroe 2020-02-19 20:31:29 -05:00
parent ab94728913
commit d5c4e7e371
1 changed files with 9 additions and 14 deletions

21
ui.c
View File

@ -493,7 +493,7 @@ static void windowScrollUnread(struct Window *window) {
} }
static int wordWidth(const char *str) { static int wordWidth(const char *str) {
size_t len = strcspn(str, " "); size_t len = strcspn(str, " \t");
int width = 0; int width = 0;
while (len) { while (len) {
wchar_t wc; wchar_t wc;
@ -515,18 +515,10 @@ static int wordWrap(WINDOW *win, const char *str) {
int align = 0; int align = 0;
struct Style style = Reset; struct Style style = Reset;
while (*str) { while (*str) {
if (*str == '\t') { char ch = *str;
if (align) { if (ch == ' ' || ch == '\t') {
waddch(win, '\t');
str++;
} else {
waddch(win, ' ');
getyx(win, y, align);
str++;
}
} else if (*str == ' ') {
getyx(win, y, x); getyx(win, y, x);
const char *word = &str[strspn(str, " ")]; const char *word = &str[strspn(str, " \t")];
if (width - x - 1 <= wordWidth(word)) { if (width - x - 1 <= wordWidth(word)) {
lines += 1 + (align + wordWidth(word)) / width; lines += 1 + (align + wordWidth(word)) / width;
waddch(win, '\n'); waddch(win, '\n');
@ -534,10 +526,13 @@ static int wordWrap(WINDOW *win, const char *str) {
wmove(win, y, align); wmove(win, y, align);
str = word; str = word;
} else { } else {
waddch(win, ' '); waddch(win, (align ? ch : ' '));
str++; str++;
} }
} }
if (ch == '\t' && !align) {
getyx(win, y, align);
}
size_t len = styleParse(&style, &str); size_t len = styleParse(&style, &str);
size_t ws = strcspn(str, " \t"); size_t ws = strcspn(str, " \t");