mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
fix(input): use click number of last click for mouse drag (#20300)
This commit is contained in:
@@ -306,37 +306,35 @@ static uint8_t check_multiclick(int code, int grid, int row, int col)
|
|||||||
static int orig_mouse_row = 0;
|
static int orig_mouse_row = 0;
|
||||||
static uint64_t orig_mouse_time = 0; // time of previous mouse click
|
static uint64_t orig_mouse_time = 0; // time of previous mouse click
|
||||||
|
|
||||||
if (code == KE_LEFTRELEASE
|
if ((code >= KE_MOUSEDOWN && code <= KE_MOUSERIGHT) || code == KE_MOUSEMOVE) {
|
||||||
|| code == KE_RIGHTRELEASE
|
|
||||||
|| code == KE_MIDDLERELEASE
|
|
||||||
|| code == KE_MOUSEDOWN
|
|
||||||
|| code == KE_MOUSEUP
|
|
||||||
|| code == KE_MOUSELEFT
|
|
||||||
|| code == KE_MOUSERIGHT
|
|
||||||
|| code == KE_MOUSEMOVE) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
uint64_t mouse_time = os_hrtime(); // time of current mouse click (ns)
|
|
||||||
|
|
||||||
// compute the time elapsed since the previous mouse click and
|
// For click events the number of clicks is updated.
|
||||||
// convert p_mouse from ms to ns
|
if (code == KE_LEFTMOUSE || code == KE_RIGHTMOUSE || code == KE_MIDDLEMOUSE) {
|
||||||
uint64_t timediff = mouse_time - orig_mouse_time;
|
uint64_t mouse_time = os_hrtime(); // time of current mouse click (ns)
|
||||||
uint64_t mouset = (uint64_t)p_mouset * 1000000;
|
// compute the time elapsed since the previous mouse click and
|
||||||
if (code == orig_mouse_code
|
// convert p_mouse from ms to ns
|
||||||
&& timediff < mouset
|
uint64_t timediff = mouse_time - orig_mouse_time;
|
||||||
&& orig_num_clicks != 4
|
uint64_t mouset = (uint64_t)p_mouset * 1000000;
|
||||||
&& orig_mouse_grid == grid
|
if (code == orig_mouse_code
|
||||||
&& orig_mouse_col == col
|
&& timediff < mouset
|
||||||
&& orig_mouse_row == row) {
|
&& orig_num_clicks != 4
|
||||||
orig_num_clicks++;
|
&& orig_mouse_grid == grid
|
||||||
} else {
|
&& orig_mouse_col == col
|
||||||
orig_num_clicks = 1;
|
&& orig_mouse_row == row) {
|
||||||
|
orig_num_clicks++;
|
||||||
|
} else {
|
||||||
|
orig_num_clicks = 1;
|
||||||
|
}
|
||||||
|
orig_mouse_code = code;
|
||||||
|
orig_mouse_time = mouse_time;
|
||||||
}
|
}
|
||||||
orig_mouse_code = code;
|
// For drag and release events the number of clicks is kept.
|
||||||
|
|
||||||
orig_mouse_grid = grid;
|
orig_mouse_grid = grid;
|
||||||
orig_mouse_col = col;
|
orig_mouse_col = col;
|
||||||
orig_mouse_row = row;
|
orig_mouse_row = row;
|
||||||
orig_mouse_time = mouse_time;
|
|
||||||
|
|
||||||
uint8_t modifiers = 0;
|
uint8_t modifiers = 0;
|
||||||
if (orig_num_clicks == 2) {
|
if (orig_num_clicks == 2) {
|
||||||
|
@@ -648,8 +648,10 @@ describe('ui/mouse/input', function()
|
|||||||
]]}
|
]]}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('two clicks will select the word and enter VISUAL', function()
|
it('two clicks will enter VISUAL and dragging selects words', function()
|
||||||
feed('<LeftMouse><2,2><LeftMouse><2,2>')
|
feed('<LeftMouse><2,2>')
|
||||||
|
feed('<LeftRelease><2,2>')
|
||||||
|
feed('<LeftMouse><2,2>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
testing |
|
testing |
|
||||||
mouse |
|
mouse |
|
||||||
@@ -657,10 +659,38 @@ describe('ui/mouse/input', function()
|
|||||||
{0:~ }|
|
{0:~ }|
|
||||||
{2:-- VISUAL --} |
|
{2:-- VISUAL --} |
|
||||||
]])
|
]])
|
||||||
|
feed('<LeftDrag><0,1>')
|
||||||
|
screen:expect([[
|
||||||
|
testing |
|
||||||
|
^m{1:ouse} |
|
||||||
|
{1:support} and selection |
|
||||||
|
{0:~ }|
|
||||||
|
{2:-- VISUAL --} |
|
||||||
|
]])
|
||||||
|
feed('<LeftDrag><4,0>')
|
||||||
|
screen:expect([[
|
||||||
|
^t{1:esting} |
|
||||||
|
{1:mouse} |
|
||||||
|
{1:support} and selection |
|
||||||
|
{0:~ }|
|
||||||
|
{2:-- VISUAL --} |
|
||||||
|
]])
|
||||||
|
feed('<LeftDrag><14,2>')
|
||||||
|
screen:expect([[
|
||||||
|
testing |
|
||||||
|
mouse |
|
||||||
|
{1:support and selectio}^n |
|
||||||
|
{0:~ }|
|
||||||
|
{2:-- VISUAL --} |
|
||||||
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('three clicks will select the line and enter VISUAL LINE', function()
|
it('three clicks will enter VISUAL LINE and dragging selects lines', function()
|
||||||
feed('<LeftMouse><2,2><LeftMouse><2,2><LeftMouse><2,2>')
|
feed('<LeftMouse><2,2>')
|
||||||
|
feed('<LeftRelease><2,2>')
|
||||||
|
feed('<LeftMouse><2,2>')
|
||||||
|
feed('<LeftRelease><2,2>')
|
||||||
|
feed('<LeftMouse><2,2>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
testing |
|
testing |
|
||||||
mouse |
|
mouse |
|
||||||
@@ -668,10 +698,40 @@ describe('ui/mouse/input', function()
|
|||||||
{0:~ }|
|
{0:~ }|
|
||||||
{2:-- VISUAL LINE --} |
|
{2:-- VISUAL LINE --} |
|
||||||
]])
|
]])
|
||||||
|
feed('<LeftDrag><0,1>')
|
||||||
|
screen:expect([[
|
||||||
|
testing |
|
||||||
|
^m{1:ouse} |
|
||||||
|
{1:support and selection} |
|
||||||
|
{0:~ }|
|
||||||
|
{2:-- VISUAL LINE --} |
|
||||||
|
]])
|
||||||
|
feed('<LeftDrag><4,0>')
|
||||||
|
screen:expect([[
|
||||||
|
{1:test}^i{1:ng} |
|
||||||
|
{1:mouse} |
|
||||||
|
{1:support and selection} |
|
||||||
|
{0:~ }|
|
||||||
|
{2:-- VISUAL LINE --} |
|
||||||
|
]])
|
||||||
|
feed('<LeftDrag><14,2>')
|
||||||
|
screen:expect([[
|
||||||
|
testing |
|
||||||
|
mouse |
|
||||||
|
{1:support and se}^l{1:ection} |
|
||||||
|
{0:~ }|
|
||||||
|
{2:-- VISUAL LINE --} |
|
||||||
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('four clicks will enter VISUAL BLOCK', function()
|
it('four clicks will enter VISUAL BLOCK and dragging selects blockwise', function()
|
||||||
feed('<LeftMouse><2,2><LeftMouse><2,2><LeftMouse><2,2><LeftMouse><2,2>')
|
feed('<LeftMouse><2,2>')
|
||||||
|
feed('<LeftRelease><2,2>')
|
||||||
|
feed('<LeftMouse><2,2>')
|
||||||
|
feed('<LeftRelease><2,2>')
|
||||||
|
feed('<LeftMouse><2,2>')
|
||||||
|
feed('<LeftRelease><2,2>')
|
||||||
|
feed('<LeftMouse><2,2>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
testing |
|
testing |
|
||||||
mouse |
|
mouse |
|
||||||
@@ -679,6 +739,30 @@ describe('ui/mouse/input', function()
|
|||||||
{0:~ }|
|
{0:~ }|
|
||||||
{2:-- VISUAL BLOCK --} |
|
{2:-- VISUAL BLOCK --} |
|
||||||
]])
|
]])
|
||||||
|
feed('<LeftDrag><0,1>')
|
||||||
|
screen:expect([[
|
||||||
|
testing |
|
||||||
|
^m{1:ou}se |
|
||||||
|
{1:sup}port and selection |
|
||||||
|
{0:~ }|
|
||||||
|
{2:-- VISUAL BLOCK --} |
|
||||||
|
]])
|
||||||
|
feed('<LeftDrag><4,0>')
|
||||||
|
screen:expect([[
|
||||||
|
te{1:st}^ing |
|
||||||
|
mo{1:use} |
|
||||||
|
su{1:ppo}rt and selection |
|
||||||
|
{0:~ }|
|
||||||
|
{2:-- VISUAL BLOCK --} |
|
||||||
|
]])
|
||||||
|
feed('<LeftDrag><14,2>')
|
||||||
|
screen:expect([[
|
||||||
|
testing |
|
||||||
|
mouse |
|
||||||
|
su{1:pport and se}^lection |
|
||||||
|
{0:~ }|
|
||||||
|
{2:-- VISUAL BLOCK --} |
|
||||||
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('right click extends visual selection to the clicked location', function()
|
it('right click extends visual selection to the clicked location', function()
|
||||||
|
Reference in New Issue
Block a user