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.
This commit is contained in:
Cormac Stephenson 2022-05-02 14:49:52 +01:00
parent bd8dd9ff7e
commit da942e8c2e

View file

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