Skip to content

Commit 9849a69

Browse files
committed
Allow extending word selections to non-word chars
1 parent 5f33d90 commit 9849a69

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

Diff for: docs/changelog.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,8 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
136136
- X11: use the window manager's native full-screen implementation when
137137
making windows full-screen (:iss:`1605`)
138138

139-
- Mouse selection: When extending by word, fix selection encompassing one or
140-
two non-word characters after a word when the mouse is over that character
141-
(:iss:`1616`)
139+
- Mouse selection: When extending by word, fix extending selection to non-word
140+
characters not working well (:iss:`1616`)
142141

143142
0.13.3 [2019-01-19]
144143
------------------------------

Diff for: kitty/mouse.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ multi_click(Window *w, unsigned int count) {
309309
unsigned int y1 = w->mouse_pos.cell_y, y2 = w->mouse_pos.cell_y;
310310
switch(count) {
311311
case 2:
312-
found_selection = screen_selection_range_for_word(screen, w->mouse_pos.cell_x, &y1, &y2, &start, &end);
312+
found_selection = screen_selection_range_for_word(screen, w->mouse_pos.cell_x, &y1, &y2, &start, &end, true);
313313
mode = EXTEND_WORD;
314314
break;
315315
case 3:

Diff for: kitty/screen.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -2007,13 +2007,17 @@ is_opt_word_char(char_type ch) {
20072007
}
20082008

20092009
bool
2010-
screen_selection_range_for_word(Screen *self, index_type x, index_type *y1, index_type *y2, index_type *s, index_type *e) {
2010+
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) {
20112011
if (*y1 >= self->lines || x >= self->columns) return false;
20122012
index_type start, end;
20132013
Line *line = visual_line_(self, *y1);
20142014
*y2 = *y1;
20152015
#define is_ok(x) (is_word_char((line->cpu_cells[x].ch)) || is_opt_word_char(line->cpu_cells[x].ch))
2016-
if (!is_ok(x)) return false;
2016+
if (!is_ok(x)) {
2017+
if (initial_selection) return false;
2018+
*s = x; *e = x;
2019+
return true;
2020+
}
20172021
start = x; end = x;
20182022
while(true) {
20192023
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) {
21092113
switch(self->selection.extend_mode) {
21102114
case EXTEND_WORD: {
21112115
index_type y1 = y, y2;
2112-
found = screen_selection_range_for_word(self, x, &y1, &y2, &start, &end);
2116+
found = screen_selection_range_for_word(self, x, &y1, &y2, &start, &end, false);
21132117
if (found) {
21142118
if (extending_leftwards) {
21152119
self->selection.end_x = start; self->selection.end_y = y1;
21162120
y1 = self->selection.start_y;
2117-
found = screen_selection_range_for_word(self, self->selection.start_x, &y1, &y2, &start, &end);
2121+
found = screen_selection_range_for_word(self, self->selection.start_x, &y1, &y2, &start, &end, false);
21182122
if (found) {
21192123
self->selection.start_x = end; self->selection.start_y = y2;
21202124
}
21212125
} else {
21222126
self->selection.end_x = end; self->selection.end_y = y2;
21232127
y1 = self->selection.start_y;
2124-
found = screen_selection_range_for_word(self, self->selection.start_x, &y1, &y2, &start, &end);
2128+
found = screen_selection_range_for_word(self, self->selection.start_x, &y1, &y2, &start, &end, false);
21252129
if (found) {
21262130
self->selection.start_x = start; self->selection.start_y = y1;
21272131
}

Diff for: kitty/screen.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ bool screen_invert_colors(Screen *self);
181181
void screen_update_cell_data(Screen *self, void *address, FONTS_DATA_HANDLE, bool cursor_has_moved);
182182
bool screen_is_cursor_visible(Screen *self);
183183
bool screen_selection_range_for_line(Screen *self, index_type y, index_type *start, index_type *end);
184-
bool screen_selection_range_for_word(Screen *self, index_type x, index_type *, index_type *, index_type *start, index_type *end);
184+
bool screen_selection_range_for_word(Screen *self, index_type x, index_type *, index_type *, index_type *start, index_type *end, bool);
185185
void screen_start_selection(Screen *self, index_type x, index_type y, bool, SelectionExtendMode);
186186
void screen_update_selection(Screen *self, index_type x, index_type y, bool ended);
187187
bool screen_history_scroll(Screen *self, int amt, bool upwards);

0 commit comments

Comments
 (0)