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.
This commit is contained in:
Daniel Eklöf 2020-01-04 13:19:30 +01:00
parent e28cb989d8
commit 6ee86be1bf
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -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;
}