To: vim_dev@googlegroups.com Subject: Patch 9.0.0822 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0822 Problem: Crash when dragging the statusline with a mapping. Solution: Check for valid window pointer. (issue #11427) Files: src/mouse.c, src/proto/mouse.pro, src/window.c, src/testdir/test_mapping.vim *** ../vim-9.0.0820/src/mouse.c 2022-10-13 13:17:37.519640382 +0100 --- src/mouse.c 2022-10-31 13:03:42.581779092 +0000 *************** *** 179,184 **** --- 179,196 ---- } #endif + static int mouse_got_click = FALSE; // got a click some time back + + /* + * Reset the flag that a mouse click was seen. To be called when switching tab + * page. + */ + void + reset_mouse_got_click(void) + { + mouse_got_click = FALSE; + } + /* * Do the appropriate action for the current mouse click in the current mode. * Not used for Command-line mode. *************** *** 224,230 **** int fixindent) // PUT_FIXINDENT if fixing indent necessary { static int do_always = FALSE; // ignore 'mouse' setting next time - static int got_click = FALSE; // got a click some time back int which_button; // MOUSE_LEFT, _MIDDLE or _RIGHT int is_click = FALSE; // If FALSE it's a drag or release event --- 236,241 ---- *************** *** 336,349 **** // Ignore drag and release events if we didn't get a click. if (is_click) ! got_click = TRUE; else { ! if (!got_click) // didn't get click, ignore return FALSE; ! if (!is_drag) // release, reset got_click { ! got_click = FALSE; if (in_tab_line) { in_tab_line = FALSE; --- 347,360 ---- // Ignore drag and release events if we didn't get a click. if (is_click) ! mouse_got_click = TRUE; else { ! if (!mouse_got_click) // didn't get click, ignore return FALSE; ! if (!is_drag) // release, reset mouse_got_click { ! mouse_got_click = FALSE; if (in_tab_line) { in_tab_line = FALSE; *************** *** 360,366 **** if (count > 1) stuffnumReadbuff(count); stuffcharReadbuff(Ctrl_T); ! got_click = FALSE; // ignore drag&release now return FALSE; } --- 371,377 ---- if (count > 1) stuffnumReadbuff(count); stuffcharReadbuff(Ctrl_T); ! mouse_got_click = FALSE; // ignore drag&release now return FALSE; } *************** *** 641,647 **** } # ifdef FEAT_MENU show_popupmenu(); ! got_click = FALSE; // ignore release events # endif return (jump_flags & CURSOR_MOVED) != 0; #else --- 652,658 ---- } # ifdef FEAT_MENU show_popupmenu(); ! mouse_got_click = FALSE; // ignore release events # endif return (jump_flags & CURSOR_MOVED) != 0; #else *************** *** 698,704 **** // next mouse click. if (!is_drag && oap != NULL && oap->op_type != OP_NOP) { ! got_click = FALSE; oap->motion_type = MCHAR; } --- 709,715 ---- // next mouse click. if (!is_drag && oap != NULL && oap->op_type != OP_NOP) { ! mouse_got_click = FALSE; oap->motion_type = MCHAR; } *************** *** 897,903 **** do_cmdline_cmd((char_u *)".cc"); else // location list window do_cmdline_cmd((char_u *)".ll"); ! got_click = FALSE; // ignore drag&release now } #endif --- 908,914 ---- do_cmdline_cmd((char_u *)".cc"); else // location list window do_cmdline_cmd((char_u *)".ll"); ! mouse_got_click = FALSE; // ignore drag&release now } #endif *************** *** 909,915 **** if (State & MODE_INSERT) stuffcharReadbuff(Ctrl_O); stuffcharReadbuff(Ctrl_RSB); ! got_click = FALSE; // ignore drag&release now } // Shift-Mouse click searches for the next occurrence of the word under --- 920,926 ---- if (State & MODE_INSERT) stuffcharReadbuff(Ctrl_O); stuffcharReadbuff(Ctrl_RSB); ! mouse_got_click = FALSE; // ignore drag&release now } // Shift-Mouse click searches for the next occurrence of the word under *** ../vim-9.0.0820/src/proto/mouse.pro 2022-06-27 23:15:16.000000000 +0100 --- src/proto/mouse.pro 2022-10-31 13:02:29.930135323 +0000 *************** *** 1,6 **** --- 1,7 ---- /* mouse.c */ void mouse_set_vert_scroll_step(long step); void mouse_set_hor_scroll_step(long step); + void reset_mouse_got_click(void); int do_mouse(oparg_T *oap, int c, int dir, long count, int fixindent); void ins_mouse(int c); void ins_mousescroll(int dir); *** ../vim-9.0.0820/src/window.c 2022-10-17 14:21:59.511756708 +0100 --- src/window.c 2022-10-31 13:02:42.326071212 +0000 *************** *** 4249,4254 **** --- 4249,4255 ---- { tabpage_T *tp = curtab; + reset_mouse_got_click(); #ifdef FEAT_JOB_CHANNEL leaving_window(curwin); #endif *************** *** 4464,4469 **** --- 4465,4471 ---- // Don't repeat a message in another tab page. set_keep_msg(NULL, 0); + reset_mouse_got_click(); skip_win_fix_scroll = TRUE; if (tp != curtab && leave_tabpage(tp->tp_curwin->w_buffer, trigger_leave_autocmds) == OK) *** ../vim-9.0.0820/src/testdir/test_mapping.vim 2022-10-19 14:48:10.508451674 +0100 --- src/testdir/test_mapping.vim 2022-10-31 12:47:40.498180491 +0000 *************** *** 1648,1653 **** --- 1648,1671 ---- set mouse& endfunc + func Test_mouse_drag_statusline() + set laststatus=2 + set mouse=a + func ClickExpr() + call test_setmouse(&lines - 1, 1) + return "\" + endfunc + func DragExpr() + call test_setmouse(&lines - 2, 1) + return "\" + endfunc + nnoremap ClickExpr() + nnoremap DragExpr() + + " this was causing a crash in win_drag_status_line() + call feedkeys("\:tabnew\\", 'tx') + endfunc + " Test for mapping in Insert mode func Test_mouse_drag_insert_map() set mouse=a *** ../vim-9.0.0820/src/version.c 2022-10-31 12:24:04.098680850 +0000 --- src/version.c 2022-10-31 12:49:51.190234158 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 822, /**/ -- It doesn't really matter what great things you are able to do if you don't do any of them. (Bram Moolenaar) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///