extract: consume spaces following a tab

That is, we choose to copy the tab character, and not the spaces it
represents. Most importantly, we don’t copy *both* the tab and the
spaces.
This commit is contained in:
Daniel Eklöf 2021-06-06 12:06:32 +02:00
parent 94b549f93e
commit 4d56dd430b
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -9,6 +9,7 @@ struct extraction_context {
wchar_t *buf;
size_t size;
size_t idx;
size_t tab_spaces_left;
size_t empty_count;
size_t newline_count;
bool strip_trailing_empty;
@ -191,8 +192,17 @@ extract_one(const struct terminal *term, const struct row *row,
}
ctx->empty_count = 0;
}
ctx->tab_spaces_left = 0;
}
if (cell->wc == L' ' && ctx->tab_spaces_left > 0) {
ctx->tab_spaces_left--;
return true;
}
ctx->tab_spaces_left = 0;
if (cell->wc == 0) {
ctx->empty_count++;
ctx->last_row = row;
@ -231,6 +241,19 @@ extract_one(const struct terminal *term, const struct row *row,
if (!ensure_size(ctx, 1))
goto err;
ctx->buf[ctx->idx++] = cell->wc;
if (cell->wc == L'\t') {
int next_tab_stop = term->cols - 1;
tll_foreach(term->tab_stops, it) {
if (it->item > col) {
next_tab_stop = it->item;
break;
}
}
xassert(next_tab_stop >= col);
ctx->tab_spaces_left = next_tab_stop - col;
}
}
ctx->last_row = row;