aboutsummaryrefslogtreecommitdiff
path: root/selection.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-07-14 11:17:50 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-07-14 11:17:50 +0000
commit4cf7195695e2112031c630ff1102beb0f7f57e4d (patch)
tree8bed6a6837b184f6956e1622d236017cf1ac1bda /selection.c
parentselection: foreach: don't call callback for trailing multi-character cells (diff)
selection: recognize empty padding cells in a forced linewrap
When printing a multi-column character at the end of the line, and it doesn't fit, we currently insert a forced line-wrap. This means the last character(s) on the previous line will be empty, followed by a multi-column character in the first cell on the next line. Without special code to handle this, the selection text extraction code will insert a hard newline, since this is normally the correct thing to do. Add a TODO, to consider writing a special place holder value to these padding cells.
Diffstat (limited to 'selection.c')
-rw-r--r--selection.c44
1 files changed, 35 insertions, 9 deletions
diff --git a/selection.c b/selection.c
index 3abe934c..cd3780a7 100644
--- a/selection.c
+++ b/selection.c
@@ -269,15 +269,41 @@ extract_one(struct terminal *term, struct row *row, struct cell *cell,
{
struct extract *ctx = data;
- if (ctx->last_row != NULL && row != ctx->last_row &&
- ((term->selection.kind == SELECTION_NORMAL &&
- (ctx->last_row->linebreak ||
- ctx->empty_count > 0 || cell->wc == 0)) ||
- term->selection.kind == SELECTION_BLOCK))
- {
- /* Last cell was the last column in the selection */
- ctx->buf[ctx->idx++] = L'\n';
- ctx->empty_count = 0;
+ if (ctx->last_row != NULL && row != ctx->last_row) {
+ /* New row - determine if we should insert a newline or not */
+
+ if (term->selection.kind == SELECTION_NORMAL) {
+ int width = max(1, wcwidth(cell->wc));
+
+ if (width > 1) {
+ /* Heuristict to handle force-wrapped multi-column
+ * characters */
+
+ /*
+ * TODO: maybe we should print a placeholder value to
+ * the empty cells at the end of the line when
+ * force-wrapping? Then extract() could simply skip
+ * those cells
+ */
+ ctx->empty_count -= min(width, ctx->empty_count);
+ }
+
+ else if (ctx->last_row->linebreak ||
+ ctx->empty_count > 0 ||
+ cell->wc == 0)
+ {
+ /* Row has a hard linebreak, or either last cell or
+ * current cell is empty */
+ ctx->buf[ctx->idx++] = L'\n';
+ ctx->empty_count = 0;
+ }
+ }
+
+ else if (term->selection.kind == SELECTION_BLOCK) {
+ /* Always insert a linebreak */
+ ctx->buf[ctx->idx++] = L'\n';
+ ctx->empty_count = 0;
+ }
}
if (cell->wc == 0) {