selection: insert newlines only when last column is empty

This commit is contained in:
Daniel Eklöf 2019-08-04 13:07:54 +02:00
parent e2229c7e2e
commit 8deead14e8
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

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