aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-01-04 12:53:30 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-01-04 12:53:30 +0000
commite6f04832949c97e829b21a2f5f71e268de00c7eb (patch)
treeba0c24cbb59988af6d3c62f037d4fa2d31020f75
parentselection: fix bug where first column on all rows but the first was lost (diff)
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.
-rw-r--r--selection.c14
1 files changed, 11 insertions, 3 deletions
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;
}