From 9e4834d58be88ad407b4fc82533233893897f7c6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 15 Mar 2018 12:19:45 +0530 Subject: [PATCH] Right click should only extend selection if there is an existing selection --- kitty/mouse.c | 14 ++++++-------- kitty/screen.c | 7 +++++++ kitty/screen.h | 1 + 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/kitty/mouse.c b/kitty/mouse.c index 0aa020534..e167d9c56 100644 --- a/kitty/mouse.c +++ b/kitty/mouse.c @@ -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 diff --git a/kitty/screen.c b/kitty/screen.c index f9fcec1a9..4562bb653 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -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); diff --git a/kitty/screen.h b/kitty/screen.h index 1a2b3c1ce..05e468050 100644 --- a/kitty/screen.h +++ b/kitty/screen.h @@ -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);