selection: cell count now adds one extra column per row, for \n

When we extract text, we may insert '\n' at the end of each line (or
last column of selection, for block selections).

These newlines doesn't occupy any physical cells, and thus we
must **make** room for them in the extraction buffer.
This commit is contained in:
Daniel Eklöf 2020-01-04 13:53:30 +01:00
parent 6ee86be1bf
commit e6f0483294
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -160,8 +160,15 @@ selection_cell_count(const struct terminal *term)
if (start->row == end->row)
return end->col - start->col + 1;
else {
size_t cells = term->cols - start->col;
cells += term->cols * (end->row - start->row - 1);
size_t cells = 0;
/* First row; start of selection to end of row */
cells += term->cols - start->col;
/* Full rows; add one extra column for \n */
cells += (term->cols + 1) * (end->row - start->row - 1);
/* Final row; start of row to end of selection */
cells += end->col + 1;
return cells;
}
@ -177,7 +184,8 @@ selection_cell_count(const struct terminal *term)
.col = max(start->col, end->col),
};
int cols = bottom_right.col - top_left.col + 1;
/* Add one extra column for \n */
int cols = bottom_right.col - top_left.col + 1 + 1;
int rows = bottom_right.row - top_left.row + 1;
return rows * cols;
}