Merge #5025 'input.c: Restore double click'

This commit is contained in:
Justin M. Keyes 2016-08-07 23:52:27 -04:00
commit 6da7d6890c
3 changed files with 77 additions and 27 deletions

View File

@ -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")

View File

@ -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
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;
// 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) {

View File

@ -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 },