From 9849a69afddc33f33a002182704ea20a12928ee3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 May 2019 20:20:03 +0530 Subject: [PATCH] Allow extending word selections to non-word chars --- docs/changelog.rst | 5 ++--- kitty/mouse.c | 2 +- kitty/screen.c | 14 +++++++++----- kitty/screen.h | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 95f9770d1..0be51e94b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -136,9 +136,8 @@ 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`) +- Mouse selection: When extending by word, fix extending selection to non-word + characters not working well (:iss:`1616`) 0.13.3 [2019-01-19] ------------------------------ diff --git a/kitty/mouse.c b/kitty/mouse.c index d969c977e..5ef800fdf 100644 --- a/kitty/mouse.c +++ b/kitty/mouse.c @@ -309,7 +309,7 @@ multi_click(Window *w, unsigned int count) { unsigned int y1 = w->mouse_pos.cell_y, y2 = w->mouse_pos.cell_y; switch(count) { case 2: - found_selection = screen_selection_range_for_word(screen, w->mouse_pos.cell_x, &y1, &y2, &start, &end); + found_selection = screen_selection_range_for_word(screen, w->mouse_pos.cell_x, &y1, &y2, &start, &end, true); mode = EXTEND_WORD; break; case 3: diff --git a/kitty/screen.c b/kitty/screen.c index f5f68570a..7e7b8ada4 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -2007,13 +2007,17 @@ is_opt_word_char(char_type ch) { } bool -screen_selection_range_for_word(Screen *self, index_type x, index_type *y1, index_type *y2, index_type *s, index_type *e) { +screen_selection_range_for_word(Screen *self, index_type x, index_type *y1, index_type *y2, index_type *s, index_type *e, bool initial_selection) { if (*y1 >= self->lines || x >= self->columns) return false; index_type start, end; 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)) return false; + if (!is_ok(x)) { + if (initial_selection) return false; + *s = x; *e = x; + return true; + } start = x; end = x; while(true) { while(start > 0 && is_ok(start - 1)) start--; @@ -2109,19 +2113,19 @@ screen_update_selection(Screen *self, index_type x, index_type y, bool ended) { switch(self->selection.extend_mode) { case EXTEND_WORD: { index_type y1 = y, y2; - found = screen_selection_range_for_word(self, x, &y1, &y2, &start, &end); + found = screen_selection_range_for_word(self, x, &y1, &y2, &start, &end, false); if (found) { if (extending_leftwards) { self->selection.end_x = start; self->selection.end_y = y1; y1 = self->selection.start_y; - found = screen_selection_range_for_word(self, self->selection.start_x, &y1, &y2, &start, &end); + found = screen_selection_range_for_word(self, self->selection.start_x, &y1, &y2, &start, &end, false); if (found) { self->selection.start_x = end; self->selection.start_y = y2; } } else { self->selection.end_x = end; self->selection.end_y = y2; y1 = self->selection.start_y; - found = screen_selection_range_for_word(self, self->selection.start_x, &y1, &y2, &start, &end); + found = screen_selection_range_for_word(self, self->selection.start_x, &y1, &y2, &start, &end, false); if (found) { self->selection.start_x = start; self->selection.start_y = y1; } diff --git a/kitty/screen.h b/kitty/screen.h index b134e3ab0..4eff12ee9 100644 --- a/kitty/screen.h +++ b/kitty/screen.h @@ -181,7 +181,7 @@ bool screen_invert_colors(Screen *self); void screen_update_cell_data(Screen *self, void *address, FONTS_DATA_HANDLE, bool cursor_has_moved); bool screen_is_cursor_visible(Screen *self); bool screen_selection_range_for_line(Screen *self, index_type y, index_type *start, index_type *end); -bool screen_selection_range_for_word(Screen *self, index_type x, index_type *, index_type *, index_type *start, index_type *end); +bool screen_selection_range_for_word(Screen *self, index_type x, index_type *, index_type *, index_type *start, index_type *end, bool); void screen_start_selection(Screen *self, index_type x, index_type y, bool, SelectionExtendMode); void screen_update_selection(Screen *self, index_type x, index_type y, bool ended); bool screen_history_scroll(Screen *self, int amt, bool upwards);