mirror of
https://github.com/neovim/neovim
synced 2025-07-16 17:21:49 +00:00
feat(tabline): middle mouse button now closes tab (#27522)
This commit is contained in:
@ -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.
|
• 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*
|
CHANGED FEATURES *news-changed*
|
||||||
|
|
||||||
|
@ -136,6 +136,26 @@ static void move_tab_to_mouse(void)
|
|||||||
tabpage_move(tabnr);
|
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
|
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) {
|
if (is_click && cmdwin_type == 0 && mouse_col < Columns) {
|
||||||
in_tab_line = true;
|
in_tab_line = true;
|
||||||
c1 = tab_page_click_defs[mouse_col].tabnr;
|
c1 = tab_page_click_defs[mouse_col].tabnr;
|
||||||
|
|
||||||
switch (tab_page_click_defs[mouse_col].type) {
|
switch (tab_page_click_defs[mouse_col].type) {
|
||||||
case kStlClickDisabled:
|
case kStlClickDisabled:
|
||||||
break;
|
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:
|
case kStlClickTabSwitch:
|
||||||
if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) {
|
if (which_button != MOUSE_MIDDLE) {
|
||||||
// double click opens new page
|
if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) {
|
||||||
end_visual_mode();
|
// double click opens new page
|
||||||
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();
|
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;
|
break;
|
||||||
case kStlClickFuncRun:
|
case kStlClickFuncRun:
|
||||||
call_click_def_func(tab_page_click_defs, mouse_col, which_button);
|
call_click_def_func(tab_page_click_defs, mouse_col, which_button);
|
||||||
|
@ -184,4 +184,18 @@ describe('tabline', function()
|
|||||||
]],
|
]],
|
||||||
}
|
}
|
||||||
end)
|
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)
|
end)
|
||||||
|
Reference in New Issue
Block a user