mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
vim-patch:9.0.0259: crash with mouse click when not initialized (#21282)
Problem: Crash with mouse click when not initialized.
Solution: Check TabPageIdxs[] is not NULL.
80525751c5
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
116
src/nvim/mouse.c
116
src/nvim/mouse.c
@@ -467,66 +467,68 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
|
|||||||
|
|
||||||
start_visual.lnum = 0;
|
start_visual.lnum = 0;
|
||||||
|
|
||||||
// Check for clicking in the tab page line.
|
if (tab_page_click_defs != NULL) { // only when initialized
|
||||||
if (mouse_grid <= 1 && mouse_row == 0 && firstwin->w_winrow > 0) {
|
// Check for clicking in the tab page line.
|
||||||
if (is_drag) {
|
if (mouse_grid <= 1 && mouse_row == 0 && firstwin->w_winrow > 0) {
|
||||||
if (in_tab_line) {
|
if (is_drag) {
|
||||||
move_tab_to_mouse();
|
if (in_tab_line) {
|
||||||
|
move_tab_to_mouse();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// click in a tab selects that tab page
|
||||||
|
if (is_click && cmdwin_type == 0 && mouse_col < Columns) {
|
||||||
|
in_tab_line = true;
|
||||||
|
c1 = tab_page_click_defs[mouse_col].tabnr;
|
||||||
|
switch (tab_page_click_defs[mouse_col].type) {
|
||||||
|
case kStlClickDisabled:
|
||||||
|
break;
|
||||||
|
case kStlClickTabClose: {
|
||||||
|
tabpage_T *tp;
|
||||||
|
|
||||||
|
// Close the current or specified tab page.
|
||||||
|
if (c1 == 999) {
|
||||||
|
tp = curtab;
|
||||||
|
} else {
|
||||||
|
tp = find_tabpage(c1);
|
||||||
|
}
|
||||||
|
if (tp == curtab) {
|
||||||
|
if (first_tabpage->tp_next != NULL) {
|
||||||
|
tabpage_close(false);
|
||||||
|
}
|
||||||
|
} else if (tp != NULL) {
|
||||||
|
tabpage_close_other(tp, false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case kStlClickTabSwitch:
|
||||||
|
if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) {
|
||||||
|
// double click opens new page
|
||||||
|
end_visual_mode();
|
||||||
|
tabpage_new();
|
||||||
|
tabpage_move(c1 == 0 ? 9999 : c1 - 1);
|
||||||
|
} else {
|
||||||
|
// Go to specified tab page, or next one if not clicking
|
||||||
|
// on a label.
|
||||||
|
goto_tabpage(c1);
|
||||||
|
|
||||||
|
// It's like clicking on the status line of a window.
|
||||||
|
if (curwin != old_curwin) {
|
||||||
|
end_visual_mode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case kStlClickFuncRun:
|
||||||
|
call_click_def_func(tab_page_click_defs, mouse_col, which_button);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else if (is_drag && in_tab_line) {
|
||||||
|
move_tab_to_mouse();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// click in a tab selects that tab page
|
|
||||||
if (is_click && cmdwin_type == 0 && mouse_col < Columns) {
|
|
||||||
in_tab_line = true;
|
|
||||||
c1 = tab_page_click_defs[mouse_col].tabnr;
|
|
||||||
switch (tab_page_click_defs[mouse_col].type) {
|
|
||||||
case kStlClickDisabled:
|
|
||||||
break;
|
|
||||||
case kStlClickTabClose: {
|
|
||||||
tabpage_T *tp;
|
|
||||||
|
|
||||||
// Close the current or specified tab page.
|
|
||||||
if (c1 == 999) {
|
|
||||||
tp = curtab;
|
|
||||||
} else {
|
|
||||||
tp = find_tabpage(c1);
|
|
||||||
}
|
|
||||||
if (tp == curtab) {
|
|
||||||
if (first_tabpage->tp_next != NULL) {
|
|
||||||
tabpage_close(false);
|
|
||||||
}
|
|
||||||
} else if (tp != NULL) {
|
|
||||||
tabpage_close_other(tp, false);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case kStlClickTabSwitch:
|
|
||||||
if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) {
|
|
||||||
// double click opens new page
|
|
||||||
end_visual_mode();
|
|
||||||
tabpage_new();
|
|
||||||
tabpage_move(c1 == 0 ? 9999 : c1 - 1);
|
|
||||||
} else {
|
|
||||||
// Go to specified tab page, or next one if not clicking
|
|
||||||
// on a label.
|
|
||||||
goto_tabpage(c1);
|
|
||||||
|
|
||||||
// It's like clicking on the status line of a window.
|
|
||||||
if (curwin != old_curwin) {
|
|
||||||
end_visual_mode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case kStlClickFuncRun:
|
|
||||||
call_click_def_func(tab_page_click_defs, mouse_col, which_button);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else if (is_drag && in_tab_line) {
|
|
||||||
move_tab_to_mouse();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// When 'mousemodel' is "popup" or "popup_setpos", translate mouse events:
|
// When 'mousemodel' is "popup" or "popup_setpos", translate mouse events:
|
||||||
|
@@ -147,4 +147,18 @@ func Test_tabline_20_format_items_no_overrun()
|
|||||||
set showtabline& tabline&
|
set showtabline& tabline&
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_mouse_click_in_tab()
|
||||||
|
" This used to crash because TabPageIdxs[] was not initialized
|
||||||
|
let lines =<< trim END
|
||||||
|
tabnew
|
||||||
|
set mouse=a
|
||||||
|
exe "norm \<LeftMouse>"
|
||||||
|
END
|
||||||
|
call writefile(lines, 'Xclickscript')
|
||||||
|
call RunVim([], [], "-e -s -S Xclickscript -c qa")
|
||||||
|
|
||||||
|
call delete('Xclickscript')
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Reference in New Issue
Block a user