Refactor function to not combine input and output parameters

This commit is contained in:
Kovid Goyal 2020-02-25 21:49:31 +05:30
parent e2a603dcda
commit c4b2de8939
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 8 additions and 9 deletions

View File

@ -337,8 +337,7 @@ multi_click(Window *w, unsigned int count) {
unsigned int y1, y2;
switch(count) {
case 2:
y1 = w->mouse_pos.cell_y;
if (screen_selection_range_for_word(screen, w->mouse_pos.cell_x, &y1, &y2, &start, &end, true)) mode = EXTEND_WORD;
if (screen_selection_range_for_word(screen, w->mouse_pos.cell_x, w->mouse_pos.cell_y, &y1, &y2, &start, &end, true)) mode = EXTEND_WORD;
break;
case 3:
if (screen_selection_range_for_line(screen, w->mouse_pos.cell_y, &start, &end)) mode = EXTEND_LINE;

View File

@ -2107,11 +2107,12 @@ 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, bool initial_selection) {
if (*y1 >= self->lines || x >= self->columns) return false;
screen_selection_range_for_word(Screen *self, const index_type x, const index_type y, index_type *y1, index_type *y2, index_type *s, index_type *e, bool initial_selection) {
if (y >= self->lines || x >= self->columns) return false;
index_type start, end;
Line *line = visual_line_(self, *y1);
*y2 = *y1;
Line *line = visual_line_(self, y);
*y1 = y;
*y2 = y;
#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)) {
if (initial_selection) return false;
@ -2224,8 +2225,7 @@ screen_update_selection(Screen *self, index_type x, index_type y, bool in_left_h
if (left_to_right && in_left_half_of_cell && x) effective_x--;
else if(!left_to_right && !in_left_half_of_cell && x < self->columns - 1) effective_x++;
}
start.y = y;
found = screen_selection_range_for_word(self, effective_x, &start.y, &end.y, &start.x, &end.x, false);
found = screen_selection_range_for_word(self, effective_x, y, &start.y, &end.y, &start.x, &end.x, false);
if (found) {
start.in_left_half_of_cell = true; end.in_left_half_of_cell = false;
if (selection_boundary_less_than(&start, a)) *a = start;

View File

@ -194,7 +194,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);
bool screen_selection_range_for_word(Screen *self, const index_type x, const index_type y, index_type *, index_type *, index_type *start, index_type *end, bool);
void screen_start_selection(Screen *self, index_type x, index_type y, bool, bool, SelectionExtendMode);
void screen_update_selection(Screen *self, index_type x, index_type y, bool in_left_half, bool ended, bool start_extended_selection);
bool screen_history_scroll(Screen *self, int amt, bool upwards);