Allow extending word selections to non-word chars

This commit is contained in:
Kovid Goyal 2019-05-16 20:20:03 +05:30
parent 5f33d907aa
commit 9849a69afd
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 13 additions and 10 deletions

View File

@ -136,9 +136,8 @@ 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 - Mouse selection: When extending by word, fix extending selection to non-word
two non-word characters after a word when the mouse is over that character characters not working well (:iss:`1616`)
(:iss:`1616`)
0.13.3 [2019-01-19] 0.13.3 [2019-01-19]
------------------------------ ------------------------------

View File

@ -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; unsigned int y1 = w->mouse_pos.cell_y, y2 = w->mouse_pos.cell_y;
switch(count) { switch(count) {
case 2: 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; mode = EXTEND_WORD;
break; break;
case 3: case 3:

View File

@ -2007,13 +2007,17 @@ is_opt_word_char(char_type ch) {
} }
bool 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; if (*y1 >= self->lines || x >= self->columns) return false;
index_type start, end; index_type start, end;
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)) return false; if (!is_ok(x)) {
if (initial_selection) return false;
*s = x; *e = x;
return true;
}
start = x; end = x; start = x; end = x;
while(true) { while(true) {
while(start > 0 && is_ok(start - 1)) start--; 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) { switch(self->selection.extend_mode) {
case EXTEND_WORD: { case EXTEND_WORD: {
index_type y1 = y, y2; 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 (found) {
if (extending_leftwards) { if (extending_leftwards) {
self->selection.end_x = start; self->selection.end_y = y1; self->selection.end_x = start; self->selection.end_y = y1;
y1 = self->selection.start_y; 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) { if (found) {
self->selection.start_x = end; self->selection.start_y = y2; self->selection.start_x = end; self->selection.start_y = y2;
} }
} else { } else {
self->selection.end_x = end; self->selection.end_y = y2; self->selection.end_x = end; self->selection.end_y = y2;
y1 = self->selection.start_y; 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) { if (found) {
self->selection.start_x = start; self->selection.start_y = y1; self->selection.start_x = start; self->selection.start_y = y1;
} }

View File

@ -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); 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_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_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_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); void screen_update_selection(Screen *self, index_type x, index_type y, bool ended);
bool screen_history_scroll(Screen *self, int amt, bool upwards); bool screen_history_scroll(Screen *self, int amt, bool upwards);