aboutsummaryrefslogtreecommitdiff
path: root/selection.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-08-04 11:07:54 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-08-04 11:07:54 +0000
commit8deead14e81ac53405b668df3332b1f84f8f658d (patch)
tree15ed7408484867b66d2230b4e8b4d2732dae716f /selection.c
parentosc: bug: uneven clipboard bytes where not buffered correctly (diff)
selection: insert newlines only when last column is empty
Diffstat (limited to 'selection.c')
-rw-r--r--selection.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/selection.c b/selection.c
index bc35fde9..92bc7514 100644
--- a/selection.c
+++ b/selection.c
@@ -56,11 +56,14 @@ extract_selection(const struct terminal *term)
if (row == NULL)
continue;
- /* TODO: replace '\0' with spaces, then trim lines */
+ /* TODO: replace '\0' with spaces, then trim lines? */
for (int col = start_col; col < term->cols; col++) {
const struct cell *cell = &row->cells[col];
- if (cell->wc == 0)
+ if (cell->wc == 0) {
+ if (col == term->cols - 1)
+ buf[idx++] = '\n';
continue;
+ }
mbstate_t ps = {0};
size_t len = wcrtomb(&buf[idx], cell->wc, &ps);
@@ -68,9 +71,6 @@ extract_selection(const struct terminal *term)
idx += len;
}
- if (r != end->row - 1)
- buf[idx++] = '\n';
-
start_col = 0;
}
@@ -78,8 +78,11 @@ extract_selection(const struct terminal *term)
const struct row *row = grid_row_in_view(term->grid, end->row - term->grid->view);
for (int col = start_col; row != NULL && col <= end->col; col++) {
const struct cell *cell = &row->cells[col];
- if (cell->wc == 0)
+ if (cell->wc == 0) {
+ if (col == term->cols - 1)
+ buf[idx++] = '\n';
continue;
+ }
mbstate_t ps = {0};
size_t len = wcrtomb(&buf[idx], cell->wc, &ps);
@@ -88,7 +91,11 @@ extract_selection(const struct terminal *term)
}
}
- buf[idx] = '\0';
+ if (buf[idx - 1] == '\n')
+ buf[idx - 1] = '\0';
+ else
+ buf[idx] = '\0';
+
return buf;
}