# HG changeset patch # User Bram Moolenaar # Date 1638207903 -3600 # Node ID 8b7f01b39d79d065fa1e1b8bbad989dac361b7b6 # Parent 6dd0e218c74e73c3828b570866a7a9ee3f407149 patch 8.2.3697: cannot drag a popup without a border Commit: https://github.com/vim/vim/commit/0b74d00693f2ff5f45cb5808197df7d1aaa5cb41 Author: Bram Moolenaar Date: Mon Nov 29 17:38:02 2021 +0000 patch 8.2.3697: cannot drag a popup without a border Problem: Cannot drag a popup without a border. Solution: Add the "dragall" option. (closes https://github.com/vim/vim/issues/9218) diff --git a/runtime/doc/popup.txt b/runtime/doc/popup.txt --- a/runtime/doc/popup.txt +++ b/runtime/doc/popup.txt @@ -681,6 +681,9 @@ The second argument of |popup_create()| popup does not have a border. As soon as dragging starts and "pos" is "center" it is changed to "topleft". + dragall TRUE to allow the popup to be dragged from every + position. Makes it very difficult to select text in + the popup. resize TRUE to allow the popup to be resized with the mouse by grabbing at the bottom right corner. Has no effect if the popup does not have a border. diff --git a/src/mouse.c b/src/mouse.c --- a/src/mouse.c +++ b/src/mouse.c @@ -1636,8 +1636,9 @@ retnomove: { return IN_UNKNOWN; } - else if ((wp->w_popup_flags & (POPF_DRAG | POPF_RESIZE)) + else if (((wp->w_popup_flags & (POPF_DRAG | POPF_RESIZE)) && popup_on_border(wp, row, col)) + || (wp->w_popup_flags & POPF_DRAGALL)) { popup_dragwin = wp; popup_start_drag(wp, row, col); diff --git a/src/popupwin.c b/src/popupwin.c --- a/src/popupwin.c +++ b/src/popupwin.c @@ -297,7 +297,7 @@ popup_drag(win_T *wp) return; } - if (!(wp->w_popup_flags & POPF_DRAG)) + if (!(wp->w_popup_flags & (POPF_DRAG | POPF_DRAGALL))) return; wp->w_wantline = drag_start_wantline + (mouse_row - drag_start_row); if (wp->w_wantline < 1) @@ -687,6 +687,14 @@ apply_general_options(win_T *wp, dict_T else wp->w_popup_flags &= ~POPF_DRAG; } + nr = dict_get_bool(dict, (char_u *)"dragall", -1); + if (nr != -1) + { + if (nr) + wp->w_popup_flags |= POPF_DRAGALL; + else + wp->w_popup_flags &= ~POPF_DRAGALL; + } nr = dict_get_bool(dict, (char_u *)"posinvert", -1); if (nr != -1) @@ -2358,7 +2366,7 @@ filter_handle_drag(win_T *wp, int c, typ int row = mouse_row; int col = mouse_col; - if ((wp->w_popup_flags & POPF_DRAG) + if ((wp->w_popup_flags & (POPF_DRAG | POPF_DRAGALL)) && is_mouse_key(c) && (wp == popup_dragwin || wp == mouse_find_win(&row, &col, FIND_POPUP))) @@ -3078,6 +3086,8 @@ f_popup_getoptions(typval_T *argvars, ty dict_add_string(dict, "title", wp->w_popup_title); dict_add_number(dict, "wrap", wp->w_p_wrap); dict_add_number(dict, "drag", (wp->w_popup_flags & POPF_DRAG) != 0); + dict_add_number(dict, "dragall", + (wp->w_popup_flags & POPF_DRAGALL) != 0); dict_add_number(dict, "mapping", (wp->w_popup_flags & POPF_MAPPING) != 0); dict_add_number(dict, "resize", (wp->w_popup_flags & POPF_RESIZE) != 0); diff --git a/src/testdir/dumps/Test_popupwin_drag_05.dump b/src/testdir/dumps/Test_popupwin_drag_05.dump new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_popupwin_drag_05.dump @@ -0,0 +1,10 @@ +>1+0&#ffffff0| @35||+1&&|1+0&&| @35 +|2| @35||+1&&|2+0&&| @35 +|3| @2|h+0#0000001#ffd7ff255|e|l@1|o| +0#0000000#ffffff0@27||+1&&|3+0&&| @35 +|4| @35||+1&&|4+0&&| @35 +|[+3&&|N|o| |N|a|m|e|]| |[|+|]| @5|1|,|1| @11|T|o|p| |[+1&&|N|o| |N|a|m|e|]| |[|+|]| @5|1|,|1| @11|T|o|p +|1+0&&| @35||+1&&|1+0&&| @35 +|2| @35||+1&&|2+0&&| @35 +|3| @35||+1&&|3+0&&| @35 +|[+1&&|N|o| |N|a|m|e|]| |[|+|]| @5|1|,|1| @11|T|o|p| |[|N|o| |N|a|m|e|]| |[|+|]| @5|1|,|1| @11|T|o|p +|:+0&&|c|a|l@1| |D|r|a|g|A|l@1|S|t|a|r|t|(|)| @54 diff --git a/src/testdir/dumps/Test_popupwin_drag_06.dump b/src/testdir/dumps/Test_popupwin_drag_06.dump new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_popupwin_drag_06.dump @@ -0,0 +1,10 @@ +>1+0&#ffffff0| @35||+1&&|1+0&&| @35 +|2| @35||+1&&|2+0&&| @35 +|3| @35||+1&&|3+0&&| @35 +|4| @35||+1&&|4+0&&| @35 +|[+3&&|N|o| |N|a|m|e|]| |[|+|]| @5|1|,|1| @11|T|h+0#0000001#ffd7ff255|e|l@1|o|o+1#0000000#ffffff0| |N|a|m|e|]| |[|+|]| @5|1|,|1| @11|T|o|p +|1+0&&| @35||+1&&|1+0&&| @35 +|2| @35||+1&&|2+0&&| @35 +|3| @35||+1&&|3+0&&| @35 +|[+1&&|N|o| |N|a|m|e|]| |[|+|]| @5|1|,|1| @11|T|o|p| |[|N|o| |N|a|m|e|]| |[|+|]| @5|1|,|1| @11|T|o|p +|:+0&&|c|a|l@1| |D|r|a|g|A|l@1|D|r|a|g|(|)| @55 diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim --- a/src/testdir/test_popupwin.vim +++ b/src/testdir/test_popupwin.vim @@ -565,22 +565,31 @@ func Test_popup_drag() \ line: &lines - 4, \ }) func Dragit() + map :call test_setmouse(&lines - 4, &columns / 2) + map :call test_setmouse(&lines - 8, &columns / 2 - 20) call feedkeys("\\\\\", "xt") endfunc - map :call test_setmouse(&lines - 4, &columns / 2) - map :call test_setmouse(&lines - 8, &columns / 2 - 20) func Resize() + map :call test_setmouse(6, 21) + map :call test_setmouse(7, 25) call feedkeys("\\\\\", "xt") endfunc - map :call test_setmouse(6, 21) - map :call test_setmouse(7, 25) func ClickAndDrag() - call feedkeys("\\\", "xt") - call feedkeys("\\\\\", "xt") + map :call test_setmouse(5, 2) + map :call test_setmouse(3, 14) + map :call test_setmouse(3, 18) + call feedkeys("\\\", "xt") + call feedkeys("\\\\\", "xt") endfunc - map :call test_setmouse(5, 2) - map :call test_setmouse(3, 14) - map :call test_setmouse(3, 18) + func DragAllStart() + call popup_clear() + call popup_create('hello', #{line: 3, col: 5, dragall: 1}) + endfunc + func DragAllDrag() + map :call test_setmouse(3, 5) + map :call test_setmouse(5, 36) + call feedkeys("\\\\\", "xt") + endfunc END call writefile(lines, 'XtestPopupDrag') let buf = RunVimInTerminal('-S XtestPopupDrag', #{rows: 10}) @@ -596,6 +605,12 @@ func Test_popup_drag() call term_sendkeys(buf, ":call ClickAndDrag()\") call VerifyScreenDump(buf, 'Test_popupwin_drag_04', {}) + " dragging without border + call term_sendkeys(buf, ":call DragAllStart()\") + call VerifyScreenDump(buf, 'Test_popupwin_drag_05', {}) + call term_sendkeys(buf, ":call DragAllDrag()\") + call VerifyScreenDump(buf, 'Test_popupwin_drag_06', {}) + " clean up call StopVimInTerminal(buf) call delete('XtestPopupDrag') diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -758,6 +758,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3697, +/**/ 3696, /**/ 3695, diff --git a/src/vim.h b/src/vim.h --- a/src/vim.h +++ b/src/vim.h @@ -638,12 +638,13 @@ extern int (*dyn_libintl_wputenv)(const #define POPF_HIDDEN 0x02 // popup is not displayed #define POPF_CURSORLINE 0x04 // popup is highlighting at the cursorline #define POPF_ON_CMDLINE 0x08 // popup overlaps command line -#define POPF_DRAG 0x10 // popup can be moved by dragging -#define POPF_RESIZE 0x20 // popup can be resized by dragging -#define POPF_MAPPING 0x40 // mapping keys -#define POPF_INFO 0x80 // used for info of popup menu -#define POPF_INFO_MENU 0x100 // align info popup with popup menu -#define POPF_POSINVERT 0x200 // vertical position can be inverted +#define POPF_DRAG 0x10 // popup can be moved by dragging border +#define POPF_DRAGALL 0x20 // popup can be moved by dragging everywhere +#define POPF_RESIZE 0x40 // popup can be resized by dragging +#define POPF_MAPPING 0x80 // mapping keys +#define POPF_INFO 0x100 // used for info of popup menu +#define POPF_INFO_MENU 0x200 // align info popup with popup menu +#define POPF_POSINVERT 0x400 // vertical position can be inverted // flags used in w_popup_handled #define POPUP_HANDLED_1 0x01 // used by mouse_find_win()