From 6ee86be1bf881f99533cc660123c6992f19f20f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 4 Jan 2020 13:19:30 +0100 Subject: [PATCH] selection: fix bug where first column on all rows but the first was lost When extracting text from the selection, we lost the first column on all rows but the first. This is because the algorithm changed slightly when we moved to foreach_selection(); the end-of-line detection is now done on the first column of the new line, instead of the last column on the previous line. --- selection.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/selection.c b/selection.c index f81fcc85..b241d375 100644 --- a/selection.c +++ b/selection.c @@ -211,20 +211,22 @@ extract_one(struct terminal *term, struct row *row, struct cell *cell, ctx->empty_count = 0; } - else if (cell->wc == 0) + if (cell->wc == 0) { ctx->empty_count++; - - else { - /* Replace empty cells with spaces when followed by non-empty cell */ - assert(ctx->idx + ctx->empty_count <= ctx->size); - for (size_t i = 0; i < ctx->empty_count; i++) - ctx->buf[ctx->idx++] = L' '; - ctx->empty_count = 0; - - assert(ctx->idx + 1 <= ctx->size); - ctx->buf[ctx->idx++] = cell->wc; + ctx->last_row = row; + ctx->last_cell = cell; + return; } + /* Replace empty cells with spaces when followed by non-empty cell */ + assert(ctx->idx + ctx->empty_count <= ctx->size); + for (size_t i = 0; i < ctx->empty_count; i++) + ctx->buf[ctx->idx++] = L' '; + ctx->empty_count = 0; + + assert(ctx->idx + 1 <= ctx->size); + ctx->buf[ctx->idx++] = cell->wc; + ctx->last_row = row; ctx->last_cell = cell; }