diff options
-rw-r--r-- | runtime/doc/news.txt | 2 | ||||
-rw-r--r-- | src/nvim/mouse.c | 69 | ||||
-rw-r--r-- | test/functional/ui/tabline_spec.lua | 14 |
3 files changed, 55 insertions, 30 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 8c6ba38d3c..16e7d65a9f 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -316,6 +316,8 @@ The following new APIs and features were added. • Added |nvim_tabpage_set_win()| to set the current window of a tabpage. +• Clicking on a tabpage in the tabline with the middle mouse button closes it. + ============================================================================== CHANGED FEATURES *news-changed* diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index f4d1be5b2f..506a428243 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -136,6 +136,26 @@ static void move_tab_to_mouse(void) tabpage_move(tabnr); } } +/// Close the current or specified tab page. +/// +/// @param c1 tabpage number, or 999 for the current tabpage +static void mouse_tab_close(int c1) +{ + tabpage_T *tp; + + 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); + } +} static bool got_click = false; // got a click some time back @@ -487,43 +507,32 @@ bool do_mouse(oparg_T *oap, int c, int dir, int count, bool fixindent) 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) { + if (which_button != MOUSE_MIDDLE) { + 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; } + FALLTHROUGH; + case kStlClickTabClose: + mouse_tab_close(c1); break; case kStlClickFuncRun: call_click_def_func(tab_page_click_defs, mouse_col, which_button); diff --git a/test/functional/ui/tabline_spec.lua b/test/functional/ui/tabline_spec.lua index 25147a44a3..1c90b17e57 100644 --- a/test/functional/ui/tabline_spec.lua +++ b/test/functional/ui/tabline_spec.lua @@ -184,4 +184,18 @@ describe('tabline', function() ]], } end) + + it('middle-click closes tab', function() + command('tabnew') + command('tabnew') + command('tabnew') + command('tabprev') + eq({ 3, 4 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) + api.nvim_input_mouse('middle', 'press', '', 0, 0, 1) + eq({ 2, 3 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) + api.nvim_input_mouse('middle', 'press', '', 0, 0, 20) + eq({ 2, 2 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) + api.nvim_input_mouse('middle', 'press', '', 0, 0, 1) + eq({ 1, 1 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]')) + end) end) |