From 4d56dd430b5a084b2589998a03d958324aa56af1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 6 Jun 2021 12:06:32 +0200 Subject: [PATCH] extract: consume spaces following a tab MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- extract.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/extract.c b/extract.c index b9fd3331..07144597 100644 --- a/extract.c +++ b/extract.c @@ -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;