mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 10:45:16 -07:00
feat(tabline): middle mouse button now closes tab (#27522)
This commit is contained in:
parent
8f1f2a1d9f
commit
fa131de9ad
@ -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*
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user