diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-05-31 15:12:38 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-05-31 15:15:20 +0000 |
| commit | f0041882f1dab1fda828c3b9ac7e37cb3682640d (patch) | |
| tree | bcb36bec0274a0375b1d704aa9a0a38398ce4ba1 /selection.c | |
| parent | Merge branch 'environment-docs' (diff) | |
selection: pay attention to hard linebreaks when search for word boundaries
Double-clicking on a word in the left or right margin, would line-wrap
the selection if there was a non-empty cell in the corresponding
right/left margin on the prev/next line. Regardless of whether there
was a hard linebreak or not.
Script to reprouce:
!/bin/bash
cols=$(tput cols)
printf "%*coo\nbar\n" $((${cols} - 2)) f
Run, then double click either “foo” or “bar”. Neither should select
the other part.
Closes #565
Diffstat (limited to 'selection.c')
| -rw-r--r-- | selection.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/selection.c b/selection.c index f684c2fa..4862def2 100644 --- a/selection.c +++ b/selection.c @@ -258,14 +258,21 @@ selection_find_word_boundary_left(struct terminal *term, struct coord *pos, int next_col = pos->col - 1; int next_row = pos->row; + const struct row *row = grid_row_in_view(term->grid, next_row); + /* Linewrap */ if (next_col < 0) { next_col = term->cols - 1; if (--next_row < 0) break; - } - const struct row *row = grid_row_in_view(term->grid, next_row); + row = grid_row_in_view(term->grid, next_row); + + if (row->linebreak) { + /* Hard linebreak, treat as space. I.e. break selection */ + break; + } + } c = row->cells[next_col].wc; while (c >= CELL_SPACER) { @@ -330,14 +337,21 @@ selection_find_word_boundary_right(struct terminal *term, struct coord *pos, int next_col = pos->col + 1; int next_row = pos->row; + const struct row *row = grid_row_in_view(term->grid, next_row); + /* Linewrap */ if (next_col >= term->cols) { + if (row->linebreak) { + /* Hard linebreak, treat as space. I.e. break selection */ + break; + } + next_col = 0; if (++next_row >= term->rows) break; - } - const struct row *row = grid_row_in_view(term->grid, next_row); + row = grid_row_in_view(term->grid, next_row); + } c = row->cells[next_col].wc; while (c >= CELL_SPACER) { |
