diff options
-rw-r--r-- | runtime/doc/options.txt | 5 | ||||
-rw-r--r-- | src/nvim/os/input.c | 47 | ||||
-rw-r--r-- | test/functional/ui/mouse_spec.lua | 54 |
3 files changed, 78 insertions, 28 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index e00f27f9f0..60acfbf700 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -4399,9 +4399,8 @@ A jump table for the options with a short description can be found at |Q_op|. *'mousetime'* *'mouset'* 'mousetime' 'mouset' number (default 500) global - Only for GUI, Windows and Unix with xterm. Defines the maximum - time in msec between two mouse clicks for the second click to be - recognized as a multi click. + Defines the maximum time in msec between two mouse clicks for the + second click to be recognized as a multi click. *'nrformats'* *'nf'* 'nrformats' 'nf' string (default "bin,hex") diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 0c46dc96ee..a4e01b18cd 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -266,29 +266,32 @@ static unsigned int handle_mouse_event(char **ptr, uint8_t *buf, } static int orig_num_clicks = 0; - static int orig_mouse_code = 0; - static int orig_mouse_col = 0; - static int orig_mouse_row = 0; - static uint64_t orig_mouse_time = 0; // time of previous mouse click - uint64_t mouse_time = os_hrtime(); // time of current mouse click - - // compute the time elapsed since the previous mouse click and - // convert p_mouse from ms to ns - uint64_t timediff = mouse_time - orig_mouse_time; - uint64_t mouset = (uint64_t)p_mouset * 1000000; - if (mouse_code == orig_mouse_code - && timediff < mouset - && orig_num_clicks != 4 - && orig_mouse_col == mouse_col - && orig_mouse_row == mouse_row) { - orig_num_clicks++; - } else { - orig_num_clicks = 1; + if (mouse_code != KE_LEFTRELEASE && mouse_code != KE_RIGHTRELEASE + && mouse_code != KE_MIDDLERELEASE) { + static int orig_mouse_code = 0; + static int orig_mouse_col = 0; + static int orig_mouse_row = 0; + static uint64_t orig_mouse_time = 0; // time of previous mouse click + uint64_t mouse_time = os_hrtime(); // time of current mouse click (ns) + + // compute the time elapsed since the previous mouse click and + // convert p_mouse from ms to ns + uint64_t timediff = mouse_time - orig_mouse_time; + uint64_t mouset = (uint64_t)p_mouset * 1000000; + if (mouse_code == orig_mouse_code + && timediff < mouset + && orig_num_clicks != 4 + && orig_mouse_col == mouse_col + && orig_mouse_row == mouse_row) { + orig_num_clicks++; + } else { + orig_num_clicks = 1; + } + orig_mouse_code = mouse_code; + orig_mouse_col = mouse_col; + orig_mouse_row = mouse_row; + orig_mouse_time = mouse_time; } - orig_mouse_code = mouse_code; - orig_mouse_col = mouse_col; - orig_mouse_row = mouse_row; - orig_mouse_time = mouse_time; uint8_t modifiers = 0; if (orig_num_clicks == 2) { diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index 7b820347ac..fd6c62a6f6 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -16,9 +16,9 @@ describe('Mouse input', function() clear() meths.set_option('mouse', 'a') meths.set_option('listchars', 'eol:$') - -- set mouset to very high value to ensure that even in valgrind/travis, + -- set mousetime to very high value to ensure that even in valgrind/travis, -- nvim will still pick multiple clicks - meths.set_option('mouset', 5000) + meths.set_option('mousetime', 5000) screen = Screen.new(25, 5) screen:attach() screen:set_default_attr_ids({ @@ -45,7 +45,7 @@ describe('Mouse input', function() screen:detach() end) - it('left click moves cursor', function() + it('single left click moves cursor', function() feed('<LeftMouse><2,1>') screen:expect([[ testing | @@ -64,6 +64,54 @@ describe('Mouse input', function() ]]) end) + it('double left click enters visual mode', function() + feed('<LeftMouse><0,0>') + feed('<LeftRelease><0,0>') + feed('<LeftMouse><0,0>') + feed('<LeftRelease><0,0>') + screen:expect([[ + {1:testin}^g | + mouse | + support and selection | + ~ | + {2:-- VISUAL --} | + ]]) + end) + + it('triple left click enters visual line mode', function() + feed('<LeftMouse><0,0>') + feed('<LeftRelease><0,0>') + feed('<LeftMouse><0,0>') + feed('<LeftRelease><0,0>') + feed('<LeftMouse><0,0>') + feed('<LeftRelease><0,0>') + screen:expect([[ + ^t{1:esting}{3: } | + mouse | + support and selection | + ~ | + {2:-- VISUAL LINE --} | + ]]) + end) + + it('quadruple left click enters visual block mode', function() + feed('<LeftMouse><0,0>') + feed('<LeftRelease><0,0>') + feed('<LeftMouse><0,0>') + feed('<LeftRelease><0,0>') + feed('<LeftMouse><0,0>') + feed('<LeftRelease><0,0>') + feed('<LeftMouse><0,0>') + feed('<LeftRelease><0,0>') + screen:expect([[ + ^testing | + mouse | + support and selection | + ~ | + {2:-- VISUAL BLOCK --} | + ]]) + end) + describe('tabline', function() local tab_attrs = { tab = { background=Screen.colors.LightGrey, underline=true }, |