Extend selection with right click

This commit is contained in:
Vedran Sajko 2018-03-12 02:14:19 +01:00
parent 079f10eebd
commit d9fe0b2540

View File

@ -22,6 +22,8 @@ typedef enum MouseActions { PRESS, RELEASE, DRAG, MOVE } MouseAction;
#define MOTION_INDICATOR (1 << 5) #define MOTION_INDICATOR (1 << 5)
#define EXTRA_BUTTON_INDICATOR (1 << 6) #define EXTRA_BUTTON_INDICATOR (1 << 6)
int last_multi_clicks = 0;
static inline unsigned int static inline unsigned int
button_map(int button) { button_map(int button) {
switch(button) { switch(button) {
@ -147,6 +149,20 @@ drag_scroll(Window *w, OSWindow *frame) {
return false; return false;
} }
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);
}
call_boss(set_primary_selection, NULL);
}
static inline void static inline void
extend_url(Screen *screen, Line *line, index_type *x, index_type *y) { extend_url(Screen *screen, Line *line, index_type *x, index_type *y) {
unsigned int count = 0; unsigned int count = 0;
@ -246,9 +262,11 @@ HANDLER(add_click) {
q->length++; q->length++;
// Now dispatch the multi-click if any // Now dispatch the multi-click if any
if (q->length > 2 && N(1).at - N(3).at <= 2 * OPT(click_interval)) { if (q->length > 2 && N(1).at - N(3).at <= 2 * OPT(click_interval)) {
last_multi_clicks = 3;
multi_click(w, 3); multi_click(w, 3);
q->length = 0; q->length = 0;
} else if (q->length > 1 && N(1).at - N(2).at <= OPT(click_interval)) { } else if (q->length > 1 && N(1).at - N(2).at <= OPT(click_interval)) {
last_multi_clicks = 2;
multi_click(w, 2); multi_click(w, 2);
} }
#undef N #undef N
@ -278,6 +296,7 @@ HANDLER(handle_button_event) {
switch(button) { switch(button) {
case GLFW_MOUSE_BUTTON_LEFT: case GLFW_MOUSE_BUTTON_LEFT:
update_drag(true, w, is_release, modifiers); update_drag(true, w, is_release, modifiers);
last_multi_clicks = 0;
if (is_release) { if (is_release) {
if (modifiers == (int)OPT(open_url_modifiers)) { if (modifiers == (int)OPT(open_url_modifiers)) {
open_url(w); open_url(w);
@ -289,6 +308,9 @@ HANDLER(handle_button_event) {
case GLFW_MOUSE_BUTTON_MIDDLE: case GLFW_MOUSE_BUTTON_MIDDLE:
if (is_release && !modifiers) { call_boss(paste_from_selection, NULL); return; } if (is_release && !modifiers) { call_boss(paste_from_selection, NULL); return; }
break; break;
case GLFW_MOUSE_BUTTON_RIGHT:
if (is_release) { extend_selection(w); }
break;
} }
} else { } else {
int sz = encode_mouse_event(w, button, is_release ? RELEASE : PRESS, modifiers); int sz = encode_mouse_event(w, button, is_release ? RELEASE : PRESS, modifiers);