aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-11-07 17:53:30 +0800
committerGitHub <noreply@github.com>2024-11-07 17:53:30 +0800
commit5a86360400691e55fae66d60485b61360a1d3d6c (patch)
tree70532d37555cd106ba2155c408b124e285242c69
parent000129201c54d4ba391f7473d0c183f000246c3e (diff)
downloadrneovim-5a86360400691e55fae66d60485b61360a1d3d6c.tar.gz
rneovim-5a86360400691e55fae66d60485b61360a1d3d6c.tar.bz2
rneovim-5a86360400691e55fae66d60485b61360a1d3d6c.zip
test: add test for key following ignored mouse move (#31104)
-rw-r--r--src/nvim/os/input.c10
-rw-r--r--test/functional/ui/mouse_spec.lua11
2 files changed, 14 insertions, 7 deletions
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c
index f77a25768d..2d17581bac 100644
--- a/src/nvim/os/input.c
+++ b/src/nvim/os/input.c
@@ -289,8 +289,8 @@ size_t input_enqueue(String keys)
unsigned new_size
= trans_special(&ptr, (size_t)(end - ptr), (char *)buf, FSK_KEYCODE, true, NULL);
- if (new_size) {
- if ((new_size = handle_mouse_event(&ptr, buf, new_size))) {
+ if (new_size > 0) {
+ if ((new_size = handle_mouse_event(&ptr, buf, new_size)) > 0) {
input_enqueue_raw((char *)buf, new_size);
}
continue;
@@ -351,9 +351,9 @@ static uint8_t check_multiclick(int code, int grid, int row, int col, bool *skip
|| code == KE_X1MOUSE || code == KE_X2MOUSE) {
// For click events the number of clicks is updated.
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
+ // Compute the time elapsed since the previous mouse click.
uint64_t timediff = mouse_time - orig_mouse_time;
+ // Convert 'mousetime' from ms to ns.
uint64_t mouset = (uint64_t)p_mouset * 1000000;
if (code == orig_mouse_code
&& no_move
@@ -407,7 +407,7 @@ static unsigned handle_mouse_event(const char **ptr, uint8_t *buf, unsigned bufs
return bufsize;
}
- // a <[COL],[ROW]> sequence can follow and will set the mouse_row/mouse_col
+ // A <[COL],[ROW]> sequence can follow and will set the mouse_row/mouse_col
// global variables. This is ugly but its how the rest of the code expects to
// find mouse coordinates, and it would be too expensive to refactor this
// now.
diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua
index 09aa3f17b3..471ee70906 100644
--- a/test/functional/ui/mouse_spec.lua
+++ b/test/functional/ui/mouse_spec.lua
@@ -1922,17 +1922,24 @@ describe('ui/mouse/input', function()
end)
it('<MouseMove> to same location does not generate events #31103', function()
- api.nvim_input_mouse('move', '', '', 0, 0, 3)
api.nvim_set_var('mouse_move', 0)
api.nvim_set_var('mouse_move2', 0)
command('nnoremap <MouseMove> <Cmd>let g:mouse_move += 1<CR>')
command('nnoremap <2-MouseMove> <Cmd>let g:mouse_move2 += 1<CR>')
+ api.nvim_input_mouse('move', '', '', 0, 0, 3)
+ eq(1, api.nvim_get_var('mouse_move'))
+ eq(0, api.nvim_get_var('mouse_move2'))
feed('<MouseMove><3,0>')
feed('<MouseMove><3,0>')
api.nvim_input_mouse('move', '', '', 0, 0, 3)
api.nvim_input_mouse('move', '', '', 0, 0, 3)
- eq(0, api.nvim_get_var('mouse_move'))
+ eq(1, api.nvim_get_var('mouse_move'))
+ eq(0, api.nvim_get_var('mouse_move2'))
+ eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
+ feed('<MouseMove><3,0><Insert>')
+ eq(1, api.nvim_get_var('mouse_move'))
eq(0, api.nvim_get_var('mouse_move2'))
+ eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
end)
it('feeding <MouseMove> in Normal mode does not use uninitialized memory #19480', function()