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
This commit is contained in:
Kovid Goyal 2019-05-16 18:32:15 +05:30
parent 0919eda640
commit 5f33d907aa
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 23 additions and 19 deletions

View File

@ -136,6 +136,10 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- X11: use the window manager's native full-screen implementation when - X11: use the window manager's native full-screen implementation when
making windows full-screen (:iss:`1605`) 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] 0.13.3 [2019-01-19]
------------------------------ ------------------------------

View File

@ -2013,25 +2013,22 @@ screen_selection_range_for_word(Screen *self, index_type x, index_type *y1, inde
Line *line = visual_line_(self, *y1); Line *line = visual_line_(self, *y1);
*y2 = *y1; *y2 = *y1;
#define is_ok(x) (is_word_char((line->cpu_cells[x].ch)) || is_opt_word_char(line->cpu_cells[x].ch)) #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)) { if (!is_ok(x)) return false;
start = x; end = x + 1; start = x; end = x;
} else { while(true) {
start = x, end = x; while(start > 0 && is_ok(start - 1)) start--;
while(true) { if (start > 0 || !line->continued || *y1 == 0) break;
while(start > 0 && is_ok(start - 1)) start--; line = visual_line_(self, *y1 - 1);
if (start > 0 || !line->continued || *y1 == 0) break; if (!is_ok(self->columns - 1)) break;
line = visual_line_(self, *y1 - 1); (*y1)--; start = self->columns - 1;
if (!is_ok(self->columns - 1)) break; }
(*y1)--; start = self->columns - 1; line = visual_line_(self, *y2);
} while(true) {
line = visual_line_(self, *y2); while(end < self->columns - 1 && is_ok(end + 1)) end++;
while(true) { if (end < self->columns - 1 || *y2 >= self->lines - 1) break;
while(end < self->columns - 1 && is_ok(end + 1)) end++; line = visual_line_(self, *y2 + 1);
if (end < self->columns - 1 || *y2 >= self->lines - 1) break; if (!line->continued || !is_ok(0)) break;
line = visual_line_(self, *y2 + 1); (*y2)++; end = 0;
if (!line->continued || !is_ok(0)) break;
(*y2)++; end = 0;
}
} }
*s = start; *e = end; *s = start; *e = end;
return true; return true;
@ -2103,6 +2100,7 @@ screen_mark_url(Screen *self, index_type start_x, index_type start_y, index_type
void void
screen_update_selection(Screen *self, index_type x, index_type y, bool ended) { 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; 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; if (ended) self->selection.in_progress = false;
index_type start, end; 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; break;
} }