From c763db94ce5cb4918e95e5c972af3df49af23485 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 28 Feb 2020 10:28:01 +0530 Subject: [PATCH] Fix #2401 --- kitty/screen.c | 24 +++++++++++------------- kitty_tests/mouse.py | 2 ++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/kitty/screen.c b/kitty/screen.c index 72a0d9c1b..da333798c 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -2215,23 +2215,21 @@ screen_update_selection(Screen *self, index_type x, index_type y, bool in_left_h self->selection.end_scrolled_by = self->scrolled_by; SelectionBoundary start, end, *a, *b; a = &self->selection.start, b = &self->selection.end; - bool left_to_right = selection_is_left_to_right(&self->selection); switch(self->selection.extend_mode) { case EXTEND_WORD: { - if (selection_boundary_less_than(b, a)) { a = &self->selection.end; b = &self->selection.start; } - bool found = false; - index_type effective_x = x; - if (!start_extended_selection) { - if (left_to_right && in_left_half_of_cell && x) effective_x--; - else if(!left_to_right && !in_left_half_of_cell && x < self->columns - 1) effective_x++; - } - found = screen_selection_range_for_word(self, effective_x, y, &start.y, &end.y, &start.x, &end.x, false); - if (found) { - start.in_left_half_of_cell = true; end.in_left_half_of_cell = false; - if (selection_boundary_less_than(&start, a)) *a = start; - if (selection_boundary_less_than(b, &end)) *b = end; + SelectionBoundary *before = &self->selection.input_start, *after = &self->selection.input_current; + if (selection_boundary_less_than(after, before)) { before = after; after = &self->selection.input_start; } + bool found_at_start = screen_selection_range_for_word(self, before->x, before->y, &start.y, &end.y, &start.x, &end.x, true); + if (found_at_start) { + a->x = start.x; a->y = start.y; a->in_left_half_of_cell = true; + b->x = end.x; b->y = end.y; b->in_left_half_of_cell = false; + } else { + a->x = before->x; a->y = before->y; a->in_left_half_of_cell = before->in_left_half_of_cell; + b->x = a->x; b->y = a->y; b->in_left_half_of_cell = a->in_left_half_of_cell; } + bool found_at_end = screen_selection_range_for_word(self, after->x, after->y, &start.y, &end.y, &start.x, &end.x, false); + if (found_at_end) { b->x = end.x; b->y = end.y; b->in_left_half_of_cell = false; } break; } case EXTEND_LINE: { diff --git a/kitty_tests/mouse.py b/kitty_tests/mouse.py index c67d0cb33..a125c1d56 100644 --- a/kitty_tests/mouse.py +++ b/kitty_tests/mouse.py @@ -137,6 +137,8 @@ class TestMouse(BaseTest): self.ae(sel(), 'ab ') move(3.6) self.ae(sel(), 'ab cd') + move(2.6) + self.ae(sel(), 'ab ') release(3.6, 1) self.ae(sel(), 'ab cd f gh') multi_click(x=1, y=2)