]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0525: Right release selects immediately when pum is truncated. v9.1.0525
authorzeertzjq <zeertzjq@outlook.com>
Thu, 4 Jul 2024 15:26:37 +0000 (17:26 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 4 Jul 2024 15:26:37 +0000 (17:26 +0200)
Problem:  Right release selects immediately when pum is truncated.
Solution: Use pum_height instead of pum_size when checking click row.
          Don't place it above mouse row when there is more space below.
          (zeertzjq)

fixes: #15101
closes: #15102

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/popupmenu.c
src/testdir/test_menu.vim
src/version.c

index 6e9d8264732421af53420c9ed17cab2235a90b2a..c18c97f7b84edd55b15e7cb80c8ce1f603690d43 100644 (file)
@@ -1332,9 +1332,10 @@ pum_set_event_info(dict_T *dict)
     static void
 pum_position_at_mouse(int min_width)
 {
-    if (Rows - mouse_row > pum_size)
+    if (Rows - mouse_row > pum_size || Rows - mouse_row > mouse_row)
     {
-       // Enough space below the mouse row.
+       // Enough space below the mouse row,
+       // or there is more space below the mouse row than above.
        pum_row = mouse_row + 1;
        if (pum_height > Rows - pum_row)
            pum_height = Rows - pum_row;
@@ -1633,7 +1634,7 @@ pum_select_mouse_pos(void)
 {
     int idx = mouse_row - pum_row;
 
-    if (idx < 0 || idx >= pum_size)
+    if (idx < 0 || idx >= pum_height)
        pum_selected = -1;
     else if (*pum_array[idx].pum_text != NUL)
        pum_selected = idx;
index 22292289eef07b9ff2d027593fdea6d96e83d596..40fec4058aad20a0b27c01c8ecefe74a4f1d0505 100644 (file)
@@ -481,13 +481,48 @@ func Test_popup_menu()
   unmenu PopUp
 endfunc
 
+func Test_popup_menu_truncated()
+  CheckNotGui
+
+  set mouse=a mousemodel=popup
+  aunmenu PopUp
+  for i in range(2 * &lines)
+    exe $'menu PopUp.{i} <Cmd>let g:res = {i}<CR>'
+  endfor
+
+  func LeftClickExpr(row, col)
+    call test_setmouse(a:row, a:col)
+    return "\<LeftMouse>"
+  endfunc
+
+  " Clicking at the bottom should place popup menu above click position.
+  " <RightRelease> should not select an item immediately.
+  let g:res = -1
+  call test_setmouse(&lines, 1)
+  nnoremap <expr><F2> LeftClickExpr(4, 1)
+  call feedkeys("\<RightMouse>\<RightRelease>\<F2>", 'tx')
+  call assert_equal(3, g:res)
+
+  " Clicking at the top should place popup menu below click position.
+  let g:res = -1
+  call test_setmouse(1, 1)
+  nnoremap <expr><F2> LeftClickExpr(5, 1)
+  call feedkeys("\<RightMouse>\<RightRelease>\<F2>", 'tx')
+  call assert_equal(3, g:res)
+
+  nunmap <F2>
+  delfunc LeftClickExpr
+  unlet g:res
+  aunmenu PopUp
+  set mouse& mousemodel&
+endfunc
+
 " Test for MenuPopup autocommand
 func Test_autocmd_MenuPopup()
   CheckNotGui
 
-  set mouse=a
-  set mousemodel=popup
-  aunmenu *
+  set mouse=a mousemodel=popup
+  aunmenu PopUp
   autocmd MenuPopup * exe printf(
     \ 'anoremenu PopUp.Foo <Cmd>let g:res = ["%s", "%s"]<CR>',
     \ expand('<afile>'), expand('<amatch>'))
index 47b60760be4bdd350164ce6254ed82d60d507d9b..66ed6a6f640ca0808e540d272664bcbc59854f5e 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    525,
 /**/
     524,
 /**/