From 5f33d907aaf42e88d45ab421e66b62db2052a1b6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 May 2019 18:32:15 +0530 Subject: [PATCH] Mouse selection: When extending by word, fix selection encompassing one or two non-word characters after a word when the mouse is over that character Fixes #1616 --- docs/changelog.rst | 4 ++++ kitty/screen.c | 38 +++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 26d717995..95f9770d1 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -136,6 +136,10 @@ To update |kitty|, :doc:`follow the instructions `. - X11: use the window manager's native full-screen implementation when making windows full-screen (:iss:`1605`) +- Mouse selection: When extending by word, fix selection encompassing one or + two non-word characters after a word when the mouse is over that character + (:iss:`1616`) + 0.13.3 [2019-01-19] ------------------------------ diff --git a/kitty/screen.c b/kitty/screen.c index 0ee56481e..f5f68570a 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -2013,25 +2013,22 @@ screen_selection_range_for_word(Screen *self, index_type x, index_type *y1, inde Line *line = visual_line_(self, *y1); *y2 = *y1; #define is_ok(x) (is_word_char((line->cpu_cells[x].ch)) || is_opt_word_char(line->cpu_cells[x].ch)) - if (!is_ok(x)) { - start = x; end = x + 1; - } else { - start = x, end = x; - while(true) { - while(start > 0 && is_ok(start - 1)) start--; - if (start > 0 || !line->continued || *y1 == 0) break; - line = visual_line_(self, *y1 - 1); - if (!is_ok(self->columns - 1)) break; - (*y1)--; start = self->columns - 1; - } - line = visual_line_(self, *y2); - while(true) { - while(end < self->columns - 1 && is_ok(end + 1)) end++; - if (end < self->columns - 1 || *y2 >= self->lines - 1) break; - line = visual_line_(self, *y2 + 1); - if (!line->continued || !is_ok(0)) break; - (*y2)++; end = 0; - } + if (!is_ok(x)) return false; + start = x; end = x; + while(true) { + while(start > 0 && is_ok(start - 1)) start--; + if (start > 0 || !line->continued || *y1 == 0) break; + line = visual_line_(self, *y1 - 1); + if (!is_ok(self->columns - 1)) break; + (*y1)--; start = self->columns - 1; + } + line = visual_line_(self, *y2); + while(true) { + while(end < self->columns - 1 && is_ok(end + 1)) end++; + if (end < self->columns - 1 || *y2 >= self->lines - 1) break; + line = visual_line_(self, *y2 + 1); + if (!line->continued || !is_ok(0)) break; + (*y2)++; end = 0; } *s = start; *e = end; return true; @@ -2103,6 +2100,7 @@ screen_mark_url(Screen *self, index_type start_x, index_type start_y, index_type void screen_update_selection(Screen *self, index_type x, index_type y, bool ended) { + index_type orig_x = self->selection.end_x, orig_y = self->selection.end_y, orig_scrolled_by = self->selection.end_scrolled_by; self->selection.end_x = x; self->selection.end_y = y; self->selection.end_scrolled_by = self->scrolled_by; if (ended) self->selection.in_progress = false; index_type start, end; @@ -2129,6 +2127,8 @@ screen_update_selection(Screen *self, index_type x, index_type y, bool ended) { } } + } else { + self->selection.end_x = orig_x; self->selection.end_y = orig_y; self->selection.end_scrolled_by = orig_scrolled_by; } break; }