diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2020-08-12 16:50:49 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2020-08-12 17:42:21 +0000 |
| commit | 8808dd28f21f7a8d75e9f0561ae5ed4a67d27895 (patch) | |
| tree | 1b5a259c88e39a3b5ff5ea9a9d5df4ee595d0ed6 /selection.c | |
| parent | doc: foot.1: don't talk about using '--' on the command line (diff) | |
selection: adjust start point when the selection changes direction
Without this, the initial cell will always be selected, regardless of
how the selection is moved to the left or right.
With this patch, the initial cell will only be selected while the
selection is being made in the original direction. Changing direction
of the selection moves the start point to next/previous character.
Diffstat (limited to 'selection.c')
| -rw-r--r-- | selection.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/selection.c b/selection.c index 356e675d..ef1269fa 100644 --- a/selection.c +++ b/selection.c @@ -320,11 +320,47 @@ selection_update(struct terminal *term, int col, int row) struct coord new_start = term->selection.start; struct coord new_end = {col, term->grid->view + row}; + /* Adjust start point if the selection has changed 'direction' */ + if (!(new_end.row == new_start.row && new_end.col == new_start.col)) { + enum selection_direction new_direction; + + if (new_end.row > new_start.row || + (new_end.row == new_start.row && new_end.col > new_start.col)) + { + /* New end point is before the start point */ + new_direction = SELECTION_RIGHT; + } else { + /* The new end point is after the start point */ + new_direction = SELECTION_LEFT; + } + + if (term->selection.direction != new_direction) { + if (term->selection.direction != SELECTION_UNDIR) { + if (new_direction == SELECTION_LEFT) { + new_start.col--; + if (new_start.col < 0) { + new_start.col = term->cols - 1; + new_start.row--; + } + } else { + new_start.col++; + if (new_start.col >= term->cols) { + new_start.col = 0; + new_start.row++; + } + } + } + + term->selection.direction = new_direction; + } + } + size_t start_row_idx = new_start.row & (term->grid->num_rows - 1); size_t end_row_idx = new_end.row & (term->grid->num_rows - 1); const struct row *row_start = term->grid->rows[start_row_idx]; const struct row *row_end = term->grid->rows[end_row_idx]; + /* Handle double-width characters */ if (new_start.row < new_end.row || (new_start.row == new_end.row && new_start.col <= new_end.col)) @@ -548,6 +584,7 @@ selection_cancel(struct terminal *term) term->selection.kind = SELECTION_NONE; term->selection.start = (struct coord){-1, -1}; term->selection.end = (struct coord){-1, -1}; + term->selection.direction = SELECTION_UNDIR; } void |
