From 05d0bda0448f0bc41ef092e1ac68ada725ec732c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 4 Jul 2021 18:49:17 +0530 Subject: [PATCH] Allow selecting blanks at the start of the top line --- kitty/screen.c | 10 ++++++++-- kitty_tests/mouse.py | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/kitty/screen.c b/kitty/screen.c index e09862e42..1795ce6a9 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -2835,8 +2835,12 @@ screen_update_selection(Screen *self, index_type x, index_type y, bool in_left_h if (upd.set_as_nearest_extend) { bool start_is_nearer = false; if (self->selections.extend_mode == EXTEND_LINE || self->selections.extend_mode == EXTEND_LINE_FROM_POINT) { - if (s->start.y == s->end.y) start_is_nearer = selection_boundary_less_than(&abs_start, &abs_end) ? (abs_current_input.y > abs_start.y) : (abs_current_input.y < abs_end.y); - else start_is_nearer = num_lines_between_selection_boundaries(&abs_start, &abs_current_input) < num_lines_between_selection_boundaries(&abs_end, &abs_current_input); + if (abs_start.y == abs_end.y) { + if (abs_current_input.y == abs_start.y) start_is_nearer = selection_boundary_less_than(&abs_start, &abs_end) ? (abs_current_input.x <= abs_start.x) : (abs_current_input.x <= abs_end.x); + else start_is_nearer = selection_boundary_less_than(&abs_start, &abs_end) ? (abs_current_input.y > abs_start.y) : (abs_current_input.y < abs_end.y); + } else { + start_is_nearer = num_lines_between_selection_boundaries(&abs_start, &abs_current_input) < num_lines_between_selection_boundaries(&abs_end, &abs_current_input); + } } else start_is_nearer = num_cells_between_selection_boundaries(self, &abs_start, &abs_current_input) < num_cells_between_selection_boundaries(self, &abs_end, &abs_current_input); if (start_is_nearer) s->adjusting_start = true; } @@ -2905,6 +2909,8 @@ screen_update_selection(Screen *self, index_type x, index_type y, bool in_left_h } else { a->in_left_half_of_cell = false; a->x = down_end.x; a->y = bottom_line; } + // allow selecting whitespace at the start of the top line + if (a->y == top_line && s->input_current.y == top_line && s->input_current.x < a->x && adjusted_boundary_is_before) a->x = s->input_current.x; } } } diff --git a/kitty_tests/mouse.py b/kitty_tests/mouse.py index 76369d739..942a764d6 100644 --- a/kitty_tests/mouse.py +++ b/kitty_tests/mouse.py @@ -179,6 +179,12 @@ class TestMouse(BaseTest): move(x=2, y=1) self.ae(sel(), '123\n 456') release() + press(x=2, y=1, button=GLFW_MOUSE_BUTTON_RIGHT) + release(x=2, y=1, button=GLFW_MOUSE_BUTTON_RIGHT) + self.ae(sel(), '123\n 456') + press(button=GLFW_MOUSE_BUTTON_RIGHT) + release(button=GLFW_MOUSE_BUTTON_RIGHT) + self.ae(sel(), ' 123\n 456') # Rectangle select init()