mirror of
https://github.com/neovim/neovim
synced 2025-07-30 10:22:07 +00:00
fix(tabline): restore behavior of click after last tabpage (#30602)
Also correct the comments about tabpage labels in custom tabline.
This commit is contained in:
@ -810,6 +810,16 @@ void draw_tabline(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int scol = col; scol < Columns; scol++) {
|
||||||
|
// Use 0 as tabpage number here, so that double-click opens a tabpage
|
||||||
|
// after the last one, and single-click goes to the next tabpage.
|
||||||
|
tab_page_click_defs[scol] = (StlClickDefinition) {
|
||||||
|
.type = kStlClickTabSwitch,
|
||||||
|
.tabnr = 0,
|
||||||
|
.func = NULL,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
char c = use_sep_chars ? '_' : ' ';
|
char c = use_sep_chars ? '_' : ' ';
|
||||||
grid_line_fill(col, Columns, schar_from_ascii(c), attr_fill);
|
grid_line_fill(col, Columns, schar_from_ascii(c), attr_fill);
|
||||||
|
|
||||||
@ -1246,24 +1256,17 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op
|
|||||||
// TABPAGE pairs are used to denote a region that when clicked will
|
// TABPAGE pairs are used to denote a region that when clicked will
|
||||||
// either switch to or close a tab.
|
// either switch to or close a tab.
|
||||||
//
|
//
|
||||||
// Ex: tabline=%0Ttab\ zero%X
|
// Ex: tabline=%1Ttab\ one%X
|
||||||
// This tabline has a TABPAGENR item with minwid `0`,
|
// This tabline has a TABPAGENR item with minwid `1`,
|
||||||
// which is then closed with a TABCLOSENR item.
|
// which is then closed with a TABCLOSENR item.
|
||||||
// Clicking on this region with mouse enabled will switch to tab 0.
|
// Clicking on this region with mouse enabled will switch to tab 1.
|
||||||
// Setting the minwid to a different value will switch
|
// Setting the minwid to a different value will switch
|
||||||
// to that tab, if it exists
|
// to that tab, if it exists
|
||||||
//
|
//
|
||||||
// Ex: tabline=%1Xtab\ one%X
|
// Ex: tabline=%1Xtab\ one%X
|
||||||
// This tabline has a TABCLOSENR item with minwid `1`,
|
// This tabline has a TABCLOSENR item with minwid `1`,
|
||||||
// which is then closed with a TABCLOSENR item.
|
// which is then closed with a TABCLOSENR item.
|
||||||
// Clicking on this region with mouse enabled will close tab 0.
|
// Clicking on this region with mouse enabled will close tab 1.
|
||||||
// This is determined by the following formula:
|
|
||||||
// tab to close = (1 - minwid)
|
|
||||||
// This is because for TABPAGENR we use `minwid` = `tab number`.
|
|
||||||
// For TABCLOSENR we store the tab number as a negative value.
|
|
||||||
// Because 0 is a valid TABPAGENR value, we have to
|
|
||||||
// start our numbering at `-1`.
|
|
||||||
// So, `-1` corresponds to us wanting to close tab `0`
|
|
||||||
//
|
//
|
||||||
// Note: These options are only valid when creating a tabline.
|
// Note: These options are only valid when creating a tabline.
|
||||||
if (*fmt_p == STL_TABPAGENR || *fmt_p == STL_TABCLOSENR) {
|
if (*fmt_p == STL_TABPAGENR || *fmt_p == STL_TABCLOSENR) {
|
||||||
|
@ -367,7 +367,7 @@ describe('ui/mouse/input', function()
|
|||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('left click in default tabline (position 4) switches to tab', function()
|
it('left click in default tabline (tabpage label) switches to tab', function()
|
||||||
feed_command('%delete')
|
feed_command('%delete')
|
||||||
insert('this is foo')
|
insert('this is foo')
|
||||||
feed_command('silent file foo | tabnew | file bar')
|
feed_command('silent file foo | tabnew | file bar')
|
||||||
@ -385,9 +385,47 @@ describe('ui/mouse/input', function()
|
|||||||
{0:~ }|*2
|
{0:~ }|*2
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
|
feed('<LeftMouse><6,0>')
|
||||||
|
screen:expect_unchanged()
|
||||||
|
feed('<LeftMouse><10,0>')
|
||||||
|
screen:expect([[
|
||||||
|
{tab: + foo }{sel: + bar }{fill: }{tab:X}|
|
||||||
|
this is ba^r{0:$} |
|
||||||
|
{0:~ }|*2
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
feed('<LeftMouse><12,0>')
|
||||||
|
screen:expect_unchanged()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('left click in default tabline (position 24) closes tab', function()
|
it('left click in default tabline (blank space) switches tab', function()
|
||||||
|
feed_command('%delete')
|
||||||
|
insert('this is foo')
|
||||||
|
feed_command('silent file foo | tabnew | file bar')
|
||||||
|
insert('this is bar')
|
||||||
|
screen:expect([[
|
||||||
|
{tab: + foo }{sel: + bar }{fill: }{tab:X}|
|
||||||
|
this is ba^r{0:$} |
|
||||||
|
{0:~ }|*2
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
feed('<LeftMouse><20,0>')
|
||||||
|
screen:expect([[
|
||||||
|
{sel: + foo }{tab: + bar }{fill: }{tab:X}|
|
||||||
|
this is fo^o |
|
||||||
|
{0:~ }|*2
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
feed('<LeftMouse><22,0>')
|
||||||
|
screen:expect([[
|
||||||
|
{tab: + foo }{sel: + bar }{fill: }{tab:X}|
|
||||||
|
this is ba^r{0:$} |
|
||||||
|
{0:~ }|*2
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('left click in default tabline (close label) closes tab', function()
|
||||||
api.nvim_set_option_value('hidden', true, {})
|
api.nvim_set_option_value('hidden', true, {})
|
||||||
feed_command('%delete')
|
feed_command('%delete')
|
||||||
insert('this is foo')
|
insert('this is foo')
|
||||||
@ -407,8 +445,7 @@ describe('ui/mouse/input', function()
|
|||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('double click in default tabline (position 4) opens new tab', function()
|
it('double click in default tabline opens new tab before', function()
|
||||||
api.nvim_set_option_value('hidden', true, {})
|
|
||||||
feed_command('%delete')
|
feed_command('%delete')
|
||||||
insert('this is foo')
|
insert('this is foo')
|
||||||
feed_command('silent file foo | tabnew | file bar')
|
feed_command('silent file foo | tabnew | file bar')
|
||||||
@ -426,6 +463,34 @@ describe('ui/mouse/input', function()
|
|||||||
{0:~ }|*2
|
{0:~ }|*2
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
|
command('tabclose')
|
||||||
|
screen:expect([[
|
||||||
|
{sel: + foo }{tab: + bar }{fill: }{tab:X}|
|
||||||
|
this is fo^o |
|
||||||
|
{0:~ }|*2
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
feed('<2-LeftMouse><20,0>')
|
||||||
|
screen:expect([[
|
||||||
|
{tab: + foo + bar }{sel: Name] }{fill: }{tab:X}|
|
||||||
|
{0:^$} |
|
||||||
|
{0:~ }|*2
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
command('tabclose')
|
||||||
|
screen:expect([[
|
||||||
|
{tab: + foo }{sel: + bar }{fill: }{tab:X}|
|
||||||
|
this is ba^r{0:$} |
|
||||||
|
{0:~ }|*2
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
feed('<2-LeftMouse><10,0>')
|
||||||
|
screen:expect([[
|
||||||
|
{tab: + foo }{sel: Name] }{tab: + bar }{fill: }{tab:X}|
|
||||||
|
{0:^$} |
|
||||||
|
{0:~ }|*2
|
||||||
|
|
|
||||||
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('%@ label', function()
|
describe('%@ label', function()
|
||||||
|
Reference in New Issue
Block a user