From da942e8c2ed98f4a552b8a4852537f001388210d Mon Sep 17 00:00:00 2001 From: Cormac Stephenson Date: Mon, 2 May 2022 14:49:52 +0100 Subject: [PATCH] selection: fix inconsistency in block selections Previously, if you made a block selection, creating a single column would set the left/right direction of a selection. This meant that: 1. Creating a single column and then dragging right created a selection which excluded the original column 2. Dragging your selection left and right would create a selection two columns wide for two consecutive cells of cursor movement So, leave the selection as SELECTION_UNDIR when appropriate and only set a pivot when the start and end columns are different. This makes the behaviour the same as char-wise selections on a single line. --- selection.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/selection.c b/selection.c index 6b57f48c..007c6ce2 100644 --- a/selection.c +++ b/selection.c @@ -812,13 +812,16 @@ selection_update(struct terminal *term, int col, int row) struct coord *pivot_end = &term->selection.pivot.end; if (term->selection.kind == SELECTION_BLOCK) { - if (new_end.col > pivot_start->col) - new_direction = SELECTION_RIGHT; - else + if (new_end.col < pivot_start->col) new_direction = SELECTION_LEFT; + else if (new_end.col > pivot_start->col || new_direction == SELECTION_LEFT) + new_direction = SELECTION_RIGHT; - if (term->selection.direction == SELECTION_UNDIR) + if (term->selection.direction == SELECTION_UNDIR && + new_end.col != new_start.col) + { set_pivot_point_for_block_and_char_wise(term, *pivot_start, new_direction); + } if (new_direction == SELECTION_LEFT) new_start = *pivot_end;