From e6f04832949c97e829b21a2f5f71e268de00c7eb Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 4 Jan 2020 13:53:30 +0100 Subject: 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. --- selection.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index b241d375..709334d4 100644 --- a/selection.c +++ b/selection.c @@ -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; } -- cgit v1.3