Skip to content

Commit

Permalink
Mouse selection: When extending by word, fix selection encompassing o…
Browse files Browse the repository at this point in the history
…ne or two non-word characters after a word when the mouse is over that character

Fixes #1616
  • Loading branch information
kovidgoyal committed May 16, 2019
1 parent 0919eda commit 5f33d90
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- 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]
------------------------------

Expand Down
38 changes: 19 additions & 19 deletions kitty/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 5f33d90

Please sign in to comment.