Right click should only extend selection if there is an existing selection

This commit is contained in:
Kovid Goyal 2018-03-15 12:19:45 +05:30
parent f38e089de0
commit 9e4834d58b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 14 additions and 8 deletions

View File

@ -22,7 +22,7 @@ typedef enum MouseActions { PRESS, RELEASE, DRAG, MOVE } MouseAction;
#define MOTION_INDICATOR (1 << 5)
#define EXTRA_BUTTON_INDICATOR (1 << 6)
int last_multi_clicks = 0;
static int last_multi_clicks = 0;
static inline unsigned int
button_map(int button) {
@ -153,14 +153,12 @@ static inline void
extend_selection(Window *w) {
Screen *screen = w->render_data.screen;
index_type start, end;
bool found_selection = false;
found_selection = screen_selection_range_for_word(screen, w->mouse_cell_x, w->mouse_cell_y, &start, &end);
if (last_multi_clicks >= 2 && found_selection) {
screen_update_selection(screen, end, w->mouse_cell_y, true);
} else {
screen_update_selection(screen, w->mouse_cell_x, w->mouse_cell_y, false);
if (screen_has_selection(screen)) {
bool found_selectable_word = screen_selection_range_for_word(screen, w->mouse_cell_x, w->mouse_cell_y, &start, &end);
if (last_multi_clicks >= 2 && found_selectable_word) screen_update_selection(screen, end, w->mouse_cell_y, true);
else screen_update_selection(screen, w->mouse_cell_x, w->mouse_cell_y, false);
call_boss(set_primary_selection, NULL);
}
call_boss(set_primary_selection, NULL);
}
static inline void

View File

@ -1397,6 +1397,13 @@ apply_selection(Screen *self, uint8_t *data, SelectionBoundary *start, Selection
}
bool
screen_has_selection(Screen *self) {
SelectionBoundary start, end;
selection_limits_(selection, &start, &end);
return !is_selection_empty(self, start.x, start.y, end.x, end.y);
}
void
screen_apply_selection(Screen *self, void *address, size_t size) {
memset(address, 0, size);

View File

@ -150,6 +150,7 @@ void report_device_status(Screen *self, unsigned int which, bool UNUSED);
void report_mode_status(Screen *self, unsigned int which, bool);
void screen_apply_selection(Screen *self, void *address, size_t size);
bool screen_is_selection_dirty(Screen *self);
bool screen_has_selection(Screen*);
bool screen_invert_colors(Screen *self);
void screen_update_cell_data(Screen *self, void *address, size_t sz);
bool screen_is_cursor_visible(Screen *self);