Patch 8.1.1920
Problem:    Cannot close a popup by the X when a filter consumes all events.
Solution:   Check for a click on the close button before invoking filters.
            (closes #4858)
Files:      src/popupwin.c, src/proto/popupwin.pro, src/ui.c,
            src/testdir/test_popupwin.vim,
            src/testdir/dumps/Test_popupwin_close_04.dump,
            src/testdir/dumps/Test_popupwin_close_05.dump


*** ../vim-8.1.1919/src/popupwin.c      2019-08-24 15:50:42.814107646 +0200
--- src/popupwin.c      2019-08-24 18:16:15.973929215 +0200
***************
*** 222,235 ****
  }
  
  /*
!  * Return TRUE if "row"/"col" is on the "X" button of the popup.
   * The values are relative to the top-left corner.
!  * Caller should check w_popup_close is POPCLOSE_BUTTON.
   */
      int
! popup_on_X_button(win_T *wp, int row, int col)
  {
!     return row == 0 && col == popup_width(wp) - 1;
  }
  
  // Values set when dragging a popup window starts.
--- 222,243 ----
  }
  
  /*
!  * Return TRUE and close the popup if "row"/"col" is on the "X" button of the
!  * popup and w_popup_close is POPCLOSE_BUTTON.
   * The values are relative to the top-left corner.
!  * Caller should check the left mouse button was clicked.
!  * Return TRUE if the popup was closed.
   */
      int
! popup_close_if_on_X(win_T *wp, int row, int col)
  {
!     if (wp->w_popup_close == POPCLOSE_BUTTON
!           && row == 0 && col == popup_width(wp) - 1)
!     {
!       popup_close_for_mouse_click(wp);
!       return TRUE;
!     }
!     return FALSE;
  }
  
  // Values set when dragging a popup window starts.
***************
*** 2635,2640 ****
--- 2643,2658 ----
  
      popup_reset_handled();
  
+     if (c == K_LEFTMOUSE)
+     {
+       int row = mouse_row;
+       int col = mouse_col;
+ 
+       wp = mouse_find_win(&row, &col, FIND_POPUP);
+       if (wp != NULL && popup_close_if_on_X(wp, row, col))
+           return TRUE;
+     }
+ 
      while (!res && (wp = find_next_popup(FALSE)) != NULL)
        if (wp->w_filter_cb.cb_name != NULL)
            res = invoke_popup_filter(wp, c);
*** ../vim-8.1.1919/src/proto/popupwin.pro      2019-08-21 18:30:58.878719490 
+0200
--- src/proto/popupwin.pro      2019-08-24 17:08:41.685133049 +0200
***************
*** 1,6 ****
  /* popupwin.c */
  int popup_on_border(win_T *wp, int row, int col);
! int popup_on_X_button(win_T *wp, int row, int col);
  void popup_start_drag(win_T *wp, int row, int col);
  void popup_drag(win_T *wp);
  void popup_set_firstline(win_T *wp);
--- 1,6 ----
  /* popupwin.c */
  int popup_on_border(win_T *wp, int row, int col);
! int popup_close_if_on_X(win_T *wp, int row, int col);
  void popup_start_drag(win_T *wp, int row, int col);
  void popup_drag(win_T *wp);
  void popup_set_firstline(win_T *wp);
*** ../vim-8.1.1919/src/ui.c    2019-08-24 14:16:28.264782382 +0200
--- src/ui.c    2019-08-24 17:07:07.373601406 +0200
***************
*** 3070,3076 ****
        if (row < 0 || col < 0)                 // check if it makes sense
            return IN_UNKNOWN;
  
!       // find the window where the row is in
        wp = mouse_find_win(&row, &col, FIND_POPUP);
        if (wp == NULL)
            return IN_UNKNOWN;
--- 3070,3077 ----
        if (row < 0 || col < 0)                 // check if it makes sense
            return IN_UNKNOWN;
  
!       // find the window where the row is in and adjust "row" and "col" to be
!       // relative to top-left of the window
        wp = mouse_find_win(&row, &col, FIND_POPUP);
        if (wp == NULL)
            return IN_UNKNOWN;
***************
*** 3083,3093 ****
        {
            on_sep_line = 0;
            in_popup_win = TRUE;
!           if (wp->w_popup_close == POPCLOSE_BUTTON
!                   && which_button == MOUSE_LEFT
!                   && popup_on_X_button(wp, row, col))
            {
-               popup_close_for_mouse_click(wp);
                return IN_UNKNOWN;
            }
            else if ((wp->w_popup_flags & (POPF_DRAG | POPF_RESIZE))
--- 3084,3091 ----
        {
            on_sep_line = 0;
            in_popup_win = TRUE;
!           if (which_button == MOUSE_LEFT && popup_close_if_on_X(wp, row, col))
            {
                return IN_UNKNOWN;
            }
            else if ((wp->w_popup_flags & (POPF_DRAG | POPF_RESIZE))
*** ../vim-8.1.1919/src/testdir/test_popupwin.vim       2019-08-24 
15:50:42.814107646 +0200
--- src/testdir/test_popupwin.vim       2019-08-24 18:17:31.461457698 +0200
***************
*** 420,425 ****
--- 420,434 ----
          call feedkeys("\<F4>\<LeftMouse>\<LeftRelease>", "xt")
        endfunc
        map <silent> <F4> :call test_setmouse(3, 17)<CR>
+       func CreateWithMenuFilter()
+         let winid = popup_create('barfoo', #{
+               \ close: 'button',
+               \ filter: 'popup_filter_menu',
+               \ border: [],
+               \ line: 1,
+               \ col: 40,
+               \ })
+       endfunc
    END
    call writefile(lines, 'XtestPopupClose')
    let buf = RunVimInTerminal('-S XtestPopupClose', #{rows: 10})
***************
*** 431,436 ****
--- 440,453 ----
    call term_sendkeys(buf, ":call CloseWithClick()\<CR>")
    call VerifyScreenDump(buf, 'Test_popupwin_close_03', {})
  
+   call term_sendkeys(buf, ":call CreateWithMenuFilter()\<CR>")
+   call VerifyScreenDump(buf, 'Test_popupwin_close_04', {})
+ 
+   " We have to send the actual mouse code, feedkeys() would be caught the
+   " filter.
+   call term_sendkeys(buf, "\<Esc>[<0;47;1M")
+   call VerifyScreenDump(buf, 'Test_popupwin_close_05', {})
+ 
    " clean up
    call StopVimInTerminal(buf)
    call delete('XtestPopupClose')
*** ../vim-8.1.1919/src/testdir/dumps/Test_popupwin_close_04.dump       
2019-08-24 18:22:24.875645424 +0200
--- src/testdir/dumps/Test_popupwin_close_04.dump       2019-08-24 
17:49:22.940519316 +0200
***************
*** 0 ****
--- 1,10 ----
+ >1+0&#ffffff0| @37|╔+0#0000001#ffd7ff255|═@5|X| +0#0000000#ffffff0@27
+ |2| @37|║+0#0000001#ffd7ff255|b|a|r|f|o@1|║| +0#0000000#ffffff0@27
+ |3| @37|╚+0#0000001#ffd7ff255|═@5|╝| +0#0000000#ffffff0@27
+ |4| @73
+ |5| |n+0#0000001#ffd7ff255|o| |b|o|r|d|e|r| |h|e|r|X| +0#0000000#ffffff0@5| 
+0#0000001#ffd7ff255@12|X| +0#0000000#ffffff0@38
+ |6| @20| +0#0000001#ffd7ff255|o|n|l|y| |p|a|d@1|i|n|g| | +0#0000000#ffffff0@38
+ |7| @20| +0#0000001#ffd7ff255@13| +0#0000000#ffffff0@38
+ |8| @73
+ |9| @73
+ |:|c|a|l@1| |C|r|e|a|t|e|W|i|t|h|M|e|n|u|F|i|l|t|e|r|(|)| @28|1|,|1| 
@10|T|o|p| 
*** ../vim-8.1.1919/src/testdir/dumps/Test_popupwin_close_05.dump       
2019-08-24 18:22:24.879645402 +0200
--- src/testdir/dumps/Test_popupwin_close_05.dump       2019-08-24 
18:15:14.462315549 +0200
***************
*** 0 ****
--- 1,10 ----
+ >1+0&#ffffff0| @73
+ |2| @73
+ |3| @73
+ |4| @73
+ |5| |n+0#0000001#ffd7ff255|o| |b|o|r|d|e|r| |h|e|r|X| +0#0000000#ffffff0@5| 
+0#0000001#ffd7ff255@12|X| +0#0000000#ffffff0@38
+ |6| @20| +0#0000001#ffd7ff255|o|n|l|y| |p|a|d@1|i|n|g| | +0#0000000#ffffff0@38
+ |7| @20| +0#0000001#ffd7ff255@13| +0#0000000#ffffff0@38
+ |8| @73
+ |9| @73
+ |:|c|a|l@1| |C|r|e|a|t|e|W|i|t|h|M|e|n|u|F|i|l|t|e|r|(|)| @28|1|,|1| 
@10|T|o|p| 
*** ../vim-8.1.1919/src/version.c       2019-08-24 15:50:42.814107646 +0200
--- src/version.c       2019-08-24 18:20:50.808223479 +0200
***************
*** 763,764 ****
--- 763,766 ----
  {   /* Add new patch number below this line */
+ /**/
+     1920,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
109. You actually read -- and enjoy -- lists like this.

 /// 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/201908241623.x7OGNd6K020036%40masaka.moolenaar.net.

Raspunde prin e-mail lui