Skip to content

Commit

Permalink
Allow extending word selections to non-word chars
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed May 16, 2019
1 parent 5f33d90 commit 9849a69
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
5 changes: 2 additions & 3 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ 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`)
- Mouse selection: When extending by word, fix extending selection to non-word
characters not working well (:iss:`1616`)

0.13.3 [2019-01-19]
------------------------------
Expand Down
2 changes: 1 addition & 1 deletion kitty/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 9 additions & 5 deletions kitty/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion kitty/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9849a69

Please sign in to comment.