]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4965: GUI: testing mouse move event depends on screen cell size v8.2.4965
authorBram Moolenaar <Bram@vim.org>
Mon, 16 May 2022 14:27:46 +0000 (15:27 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 16 May 2022 14:27:46 +0000 (15:27 +0100)
Problem:    GUI: testing mouse move event depends on screen cell size.
Solution:   Multiply the row and column with the screen cell size.

runtime/doc/testing.txt
src/testdir/test_gui.vim
src/testing.c
src/version.c

index f2f04a2aecea49c9e8b68cf69a2a1211a1742cb3..0601cb9c801f6993f8e1f2332a3fa9e3a946d511 100644 (file)
@@ -154,9 +154,12 @@ test_gui_event({event}, {args})
                    move:       Optional; if used and TRUE then a mouse move
                                event can be generated.
                                Only {args} row: and col: are used and
-                               required; they are interpreted as pixels.
+                               required; they are interpreted as pixels or
+                               screen cells, depending on "cell".
                                Only results in an event when 'mousemoveevent'
                                is set or a popup uses mouse move events.
+                   cell:       Optional: when present and TRUE then "move"
+                               uses screen cells instead of pixel positions
 
                "scrollbar":
                  Set or drag the left, right or horizontal scrollbar.  Only
index d0600c931e9329bb61895b4c27d76019352d7baa..b390d14bc598b048de3ddcba8f3bc793b64c96e2 100644 (file)
@@ -1209,66 +1209,71 @@ func PrepareForMouseEvent(args)
   endif
 endfunc
 
+func MouseWasMoved()
+  let pos = getmousepos()
+  call add(g:eventlist, #{row: pos.screenrow, col: pos.screencol})
+endfunc
+
 func Test_gui_mouse_move_event()
   let args = #{move: 1, button: 0, multiclick: 0, modifiers: 0}
 
-  " default, do not generate mouse move events
+  " by default, does not generate mouse move events
   set mousemev&
   call assert_false(&mousemev)
 
-  let g:n_event = 0
-  nnoremap <special> <MouseMove> :let g:n_event += 1<CR>
+  let g:eventlist = []
+  nnoremap <special> <silent> <MouseMove> :call MouseWasMoved()<CR>
 
   " start at mouse pos (1,1), clear counter
   call PrepareForMouseEvent(args)
-  let g:n_event = 0
+  let g:eventlist = []
 
-  call extend(args, #{row: 30, col: 300})
+  call extend(args, #{row: 3, col: 30, cell: v:true})
   call test_gui_event('mouse', args)
   call feedkeys('', 'Lx!')
 
-  call extend(args, #{row: 100, col: 300})
+  call extend(args, #{row: 10, col: 30, cell: v:true})
   call test_gui_event('mouse', args)
   call feedkeys('', 'Lx!')
 
   " no events since mousemev off
-  call assert_equal(0, g:n_event)
+  call assert_equal([], g:eventlist)
 
   " turn on mouse events and try the same thing
   set mousemev
   call PrepareForMouseEvent(args)
-  let g:n_event = 0
+  let g:eventlist = []
 
-  call extend(args, #{row: 30, col: 300})
+  call extend(args, #{row: 3, col: 30, cell: v:true})
   call test_gui_event('mouse', args)
   call feedkeys('', 'Lx!')
 
-  call extend(args, #{row: 100, col: 300})
+  call extend(args, #{row: 10, col: 30, cell: v:true})
   call test_gui_event('mouse', args)
   call feedkeys('', 'Lx!')
 
-  call assert_equal(2, g:n_event)
+  call assert_equal([#{row: 4, col: 31}, #{row: 11, col: 31}], g:eventlist)
 
-  " wiggle the mouse around, shouldn't get events
+  " wiggle the mouse around within a screen cell, shouldn't trigger events
+  call extend(args, #{cell: v:false})
   call PrepareForMouseEvent(args)
-  let g:n_event = 0
+  let g:eventlist = []
 
-  call extend(args, #{row: 1, col: 2})
+  call extend(args, #{row: 1, col: 2, cell: v:false})
   call test_gui_event('mouse', args)
   call feedkeys('', 'Lx!')
 
-  call extend(args, #{row: 2, col: 2})
+  call extend(args, #{row: 2, col: 2, cell: v:false})
   call test_gui_event('mouse', args)
   call feedkeys('', 'Lx!')
 
-  call extend(args, #{row: 2, col: 1})
+  call extend(args, #{row: 2, col: 1, cell: v:false})
   call test_gui_event('mouse', args)
   call feedkeys('', 'Lx!')
 
-  call PrepareForMouseEvent(args)
-  call assert_equal(0, g:n_event)
+  call assert_equal([], g:eventlist)
 
-  unlet g:n_event
+  unlet g:eventlist
   unmap <MouseMove>
   set mousemev&
 endfunc
index 572dcdcffe2e63b0bc1b72be0df517746f3d9212..23ab98f5c1b04de7da5a3287b74038f45b76f116 100644 (file)
@@ -1386,7 +1386,15 @@ test_gui_mouse_event(dict_T *args)
     col = (int)dict_get_number(args, (char_u *)"col");
 
     if (move)
+    {
+       if (dict_get_bool(args, (char_u *)"cell", FALSE))
+       {
+           // click in the middle of the character cell
+           row = row * gui.char_height + gui.char_height / 2;
+           col = col * gui.char_width + gui.char_width / 2;
+       }
        gui_mouse_moved(col, row);
+    }
     else
     {
        button = (int)dict_get_number(args, (char_u *)"button");
index 1b98b031c77fdc1fd8c1dd7bc003830882a70154..f36e552907b27f1e80539d083dcfa21c2cef8630 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4965,
 /**/
     4964,
 /**/