When double-clicking select words that continue onto next/prev line as well. Fixes #444
This commit is contained in:
parent
49c375ae0f
commit
e90df0ca95
@ -18,6 +18,9 @@ version 0.9.0 [future]
|
|||||||
- A new remote control command "set-colors" to change the current and/or
|
- A new remote control command "set-colors" to change the current and/or
|
||||||
configured colors.
|
configured colors.
|
||||||
|
|
||||||
|
- When double-clicking to select a word, select wrods that continue onto the
|
||||||
|
next/prev line as well.
|
||||||
|
|
||||||
- Add an "include" directive for the config files to read multiple config files
|
- Add an "include" directive for the config files to read multiple config files
|
||||||
|
|
||||||
- Improve mouse selection for windows with padding. Moving the mouse into the
|
- Improve mouse selection for windows with padding. Moving the mouse into the
|
||||||
|
|||||||
@ -260,9 +260,10 @@ multi_click(Window *w, unsigned int count) {
|
|||||||
index_type start, end;
|
index_type start, end;
|
||||||
bool found_selection = false;
|
bool found_selection = false;
|
||||||
SelectionExtendMode mode = EXTEND_CELL;
|
SelectionExtendMode mode = EXTEND_CELL;
|
||||||
|
unsigned int y1 = w->mouse_cell_y, y2 = w->mouse_cell_y;
|
||||||
switch(count) {
|
switch(count) {
|
||||||
case 2:
|
case 2:
|
||||||
found_selection = screen_selection_range_for_word(screen, w->mouse_cell_x, w->mouse_cell_y, &start, &end);
|
found_selection = screen_selection_range_for_word(screen, w->mouse_cell_x, &y1, &y2, &start, &end);
|
||||||
mode = EXTEND_WORD;
|
mode = EXTEND_WORD;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
@ -273,8 +274,8 @@ multi_click(Window *w, unsigned int count) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (found_selection) {
|
if (found_selection) {
|
||||||
screen_start_selection(screen, start, w->mouse_cell_y, false, mode);
|
screen_start_selection(screen, start, y1, false, mode);
|
||||||
screen_update_selection(screen, end, w->mouse_cell_y, false);
|
screen_update_selection(screen, end, y2, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1676,17 +1676,31 @@ is_opt_word_char(char_type ch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
screen_selection_range_for_word(Screen *self, index_type x, index_type y, 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) {
|
||||||
if (y >= 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, y);
|
Line *line = visual_line_(self, *y1);
|
||||||
|
*y2 = *y1;
|
||||||
#define is_ok(x) (is_word_char((line->cells[x].ch)) || is_opt_word_char(line->cells[x].ch))
|
#define is_ok(x) (is_word_char((line->cells[x].ch)) || is_opt_word_char(line->cells[x].ch))
|
||||||
if (!is_ok(x)) {
|
if (!is_ok(x)) {
|
||||||
start = x; end = x + 1;
|
start = x; end = x + 1;
|
||||||
} else {
|
} else {
|
||||||
start = x, end = x;
|
start = x, end = x;
|
||||||
|
while(true) {
|
||||||
while(start > 0 && is_ok(start - 1)) start--;
|
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++;
|
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;
|
*s = start; *e = end;
|
||||||
return true;
|
return true;
|
||||||
@ -1763,16 +1777,40 @@ screen_update_selection(Screen *self, index_type x, index_type y, bool ended) {
|
|||||||
index_type start, end;
|
index_type start, end;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
switch(self->selection.extend_mode) {
|
switch(self->selection.extend_mode) {
|
||||||
case EXTEND_WORD:
|
case EXTEND_WORD: {
|
||||||
found = screen_selection_range_for_word(self, x, y, &start, &end);
|
index_type y1 = y, y2;
|
||||||
|
found = screen_selection_range_for_word(self, x, &y1, &y2, &start, &end);
|
||||||
|
if (found) {
|
||||||
|
#define SMALLER(x1, y1, x2, y2) (y1 < y2 || (y1 == y2 && x1 < x2))
|
||||||
|
if (SMALLER(self->selection.end_x, self->selection.end_y, self->selection.start_x, self->selection.start_y)) {
|
||||||
|
// extend 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);
|
||||||
|
if (found) {
|
||||||
|
self->selection.start_x = end; self->selection.start_y = y2;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// extend rightwards
|
||||||
|
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);
|
||||||
|
if (found) {
|
||||||
|
self->selection.start_x = start; self->selection.start_y = y1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#undef SMALLER
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case EXTEND_LINE:
|
case EXTEND_LINE:
|
||||||
found = screen_selection_range_for_line(self, y, &start, &end);
|
found = screen_selection_range_for_line(self, y, &start, &end);
|
||||||
|
if (found) self->selection.end_x = end;
|
||||||
break;
|
break;
|
||||||
case EXTEND_CELL:
|
case EXTEND_CELL:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (found) self->selection.end_x = end;
|
|
||||||
call_boss(set_primary_selection, NULL);
|
call_boss(set_primary_selection, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -158,7 +158,7 @@ bool screen_invert_colors(Screen *self);
|
|||||||
void screen_update_cell_data(Screen *self, void *address, size_t sz);
|
void screen_update_cell_data(Screen *self, void *address, size_t sz);
|
||||||
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 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);
|
||||||
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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user