aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-06-06 10:06:32 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-06-08 17:53:26 +0000
commit4d56dd430b5a084b2589998a03d958324aa56af1 (patch)
treee3d16bfd8c6ea5277a31a3b00af54f253706e25c
parentvt: emit a tab character if all cells between cursor and tab stop are empty (diff)
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.
-rw-r--r--extract.c23
1 files changed, 23 insertions, 0 deletions
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;