Patch 8.1.2266
Problem:    Position unknown for a mouse click in a popup window.
Solution:   Set v:mouse_col and v:mouse_lnum. (closes #5171)
Files:      src/popupwin.c, src/testdir/test_popupwin.vim


*** ../vim-8.1.2265/src/popupwin.c      2019-11-06 19:25:04.853696953 +0100
--- src/popupwin.c      2019-11-06 21:01:09.130056655 +0100
***************
*** 2862,2873 ****
  
      argv[2].v_type = VAR_UNKNOWN;
  
      // NOTE: The callback might close the popup and make "wp" invalid.
      call_callback(&wp->w_filter_cb, -1, &rettv, 2, argv);
      if (win_valid_popup(wp) && old_lnum != wp->w_cursor.lnum)
        popup_highlight_curline(wp);
- 
      res = tv_get_number(&rettv);
      vim_free(argv[1].vval.v_string);
      clear_tv(&rettv);
      return res;
--- 2862,2892 ----
  
      argv[2].v_type = VAR_UNKNOWN;
  
+     if (is_mouse_key(c))
+     {
+       int             row = mouse_row - wp->w_winrow;
+       int             col = mouse_col - wp->w_wincol;
+       linenr_T        lnum;
+ 
+       if (row >= 0 && col >= 0)
+       {
+           (void)mouse_comp_pos(wp, &row, &col, &lnum, NULL);
+           set_vim_var_nr(VV_MOUSE_LNUM, lnum);
+           set_vim_var_nr(VV_MOUSE_COL, col + 1);
+       }
+     }
+ 
      // NOTE: The callback might close the popup and make "wp" invalid.
      call_callback(&wp->w_filter_cb, -1, &rettv, 2, argv);
      if (win_valid_popup(wp) && old_lnum != wp->w_cursor.lnum)
        popup_highlight_curline(wp);
      res = tv_get_number(&rettv);
+ 
+     if (is_mouse_key(c))
+     {
+       set_vim_var_nr(VV_MOUSE_LNUM, 0);
+       set_vim_var_nr(VV_MOUSE_COL, 0);
+     }
      vim_free(argv[1].vval.v_string);
      clear_tv(&rettv);
      return res;
***************
*** 2891,2898 ****
        return FALSE;
      recursive = TRUE;
  
-     popup_reset_handled();
- 
      if (c == K_LEFTMOUSE)
      {
        int row = mouse_row;
--- 2910,2915 ----
***************
*** 2903,2908 ****
--- 2920,2926 ----
            res = TRUE;
      }
  
+     popup_reset_handled();
      state = get_real_state();
      while (!res && (wp = find_next_popup(FALSE)) != NULL)
        if (wp->w_filter_cb.cb_name != NULL
*** ../vim-8.1.2265/src/testdir/test_popupwin.vim       2019-11-06 
19:25:04.857696936 +0100
--- src/testdir/test_popupwin.vim       2019-11-06 21:04:23.653277064 +0100
***************
*** 2166,2171 ****
--- 2166,2209 ----
    delfunc MyPopupFilter
  endfunc
  
+ func Test_popupwin_filter_mouse()
+   func MyPopupFilter(winid, c)
+     let g:got_mouse_col = v:mouse_col
+     let g:got_mouse_lnum = v:mouse_lnum
+     return 0
+   endfunc
+ 
+   let winid = popup_create(['short', 'long line that will wrap', 'short'], #{
+       \ line: 4,
+       \ col: 8,
+       \ maxwidth: 12,
+       \ filter: 'MyPopupFilter',
+       \ })
+   redraw
+   call test_setmouse(4, 8)
+   call feedkeys("\<LeftMouse>", 'xt')
+   call assert_equal(1, g:got_mouse_col)
+   call assert_equal(1, g:got_mouse_lnum)
+ 
+   call test_setmouse(5, 8)
+   call feedkeys("\<LeftMouse>", 'xt')
+   call assert_equal(1, g:got_mouse_col)
+   call assert_equal(2, g:got_mouse_lnum)
+ 
+   call test_setmouse(6, 8)
+   call feedkeys("\<LeftMouse>", 'xt')
+   call assert_equal(13, g:got_mouse_col)
+   call assert_equal(2, g:got_mouse_lnum)
+ 
+   call test_setmouse(7, 20)
+   call feedkeys("\<LeftMouse>", 'xt')
+   call assert_equal(13, g:got_mouse_col)
+   call assert_equal(3, g:got_mouse_lnum)
+ 
+   call popup_close(winid)
+   delfunc MyPopupFilter
+ endfunc
+ 
  func Test_popupwin_with_buffer()
    call writefile(['some text', 'in a buffer'], 'XsomeFile')
    let buf = bufadd('XsomeFile')
*** ../vim-8.1.2265/src/version.c       2019-11-06 19:25:04.857696936 +0100
--- src/version.c       2019-11-06 20:17:37.141554839 +0100
***************
*** 743,744 ****
--- 743,746 ----
  {   /* Add new patch number below this line */
+ /**/
+     2266,
  /**/

-- 
On the other hand, you have different fingers.
                                      -- Steven Wright

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/201911062009.xA6K9qMU005526%40masaka.moolenaar.net.

Raspunde prin e-mail lui