mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 21:25:04 -07:00
Merge #7782 'Fix TabClose autocommand via close_windows'
This commit is contained in:
commit
9dc90fcde1
@ -6230,7 +6230,6 @@ void tabpage_close_other(tabpage_T *tp, int forceit)
|
|||||||
if (!valid_tabpage(tp) || tp->tp_firstwin == wp)
|
if (!valid_tabpage(tp) || tp->tp_firstwin == wp)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
apply_autocmds(EVENT_TABCLOSED, prev_idx, prev_idx, FALSE, curbuf);
|
|
||||||
|
|
||||||
redraw_tabline = TRUE;
|
redraw_tabline = TRUE;
|
||||||
if (h != tabline_height())
|
if (h != tabline_height())
|
||||||
|
@ -1724,7 +1724,6 @@ void close_windows(buf_T *buf, int keep_curwin)
|
|||||||
{
|
{
|
||||||
tabpage_T *tp, *nexttp;
|
tabpage_T *tp, *nexttp;
|
||||||
int h = tabline_height();
|
int h = tabline_height();
|
||||||
int count = tabpage_index(NULL);
|
|
||||||
|
|
||||||
++RedrawingDisabled;
|
++RedrawingDisabled;
|
||||||
|
|
||||||
@ -1762,10 +1761,6 @@ void close_windows(buf_T *buf, int keep_curwin)
|
|||||||
|
|
||||||
--RedrawingDisabled;
|
--RedrawingDisabled;
|
||||||
|
|
||||||
if (count != tabpage_index(NULL)) {
|
|
||||||
apply_autocmds(EVENT_TABCLOSED, NULL, NULL, false, curbuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
redraw_tabline = true;
|
redraw_tabline = true;
|
||||||
if (h != tabline_height()) {
|
if (h != tabline_height()) {
|
||||||
shell_new_rows();
|
shell_new_rows();
|
||||||
@ -1848,7 +1843,6 @@ static bool close_last_window_tabpage(win_T *win, bool free_buf,
|
|||||||
|
|
||||||
// Since goto_tabpage_tp above did not trigger *Enter autocommands, do
|
// Since goto_tabpage_tp above did not trigger *Enter autocommands, do
|
||||||
// that now.
|
// that now.
|
||||||
apply_autocmds(EVENT_TABCLOSED, prev_idx, prev_idx, false, curbuf);
|
|
||||||
apply_autocmds(EVENT_WINENTER, NULL, NULL, false, curbuf);
|
apply_autocmds(EVENT_WINENTER, NULL, NULL, false, curbuf);
|
||||||
apply_autocmds(EVENT_TABENTER, NULL, NULL, false, curbuf);
|
apply_autocmds(EVENT_TABENTER, NULL, NULL, false, curbuf);
|
||||||
if (old_curbuf != curbuf) {
|
if (old_curbuf != curbuf) {
|
||||||
@ -2108,6 +2102,11 @@ void win_close_othertab(win_T *win, int free_buf, tabpage_T *tp)
|
|||||||
|
|
||||||
/* When closing the last window in a tab page remove the tab page. */
|
/* When closing the last window in a tab page remove the tab page. */
|
||||||
if (tp->tp_firstwin == tp->tp_lastwin) {
|
if (tp->tp_firstwin == tp->tp_lastwin) {
|
||||||
|
char_u prev_idx[NUMBUFLEN];
|
||||||
|
if (has_event(EVENT_TABCLOSED)) {
|
||||||
|
vim_snprintf((char *)prev_idx, NUMBUFLEN, "%i", tabpage_index(tp));
|
||||||
|
}
|
||||||
|
|
||||||
if (tp == first_tabpage)
|
if (tp == first_tabpage)
|
||||||
first_tabpage = tp->tp_next;
|
first_tabpage = tp->tp_next;
|
||||||
else {
|
else {
|
||||||
@ -2121,6 +2120,10 @@ void win_close_othertab(win_T *win, int free_buf, tabpage_T *tp)
|
|||||||
ptp->tp_next = tp->tp_next;
|
ptp->tp_next = tp->tp_next;
|
||||||
}
|
}
|
||||||
free_tp = TRUE;
|
free_tp = TRUE;
|
||||||
|
|
||||||
|
if (has_event(EVENT_TABCLOSED)) {
|
||||||
|
apply_autocmds(EVENT_TABCLOSED, prev_idx, prev_idx, false, win->w_buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free the memory used for the window. */
|
/* Free the memory used for the window. */
|
||||||
|
@ -2,32 +2,67 @@ local helpers = require('test.functional.helpers')(after_each)
|
|||||||
local clear, nvim, eq = helpers.clear, helpers.nvim, helpers.eq
|
local clear, nvim, eq = helpers.clear, helpers.nvim, helpers.eq
|
||||||
|
|
||||||
describe('TabClosed', function()
|
describe('TabClosed', function()
|
||||||
describe('au TabClosed', function()
|
before_each(clear)
|
||||||
describe('with * as <afile>', function()
|
|
||||||
it('matches when closing any tab', function()
|
describe('au TabClosed', function()
|
||||||
clear()
|
describe('with * as <afile>', function()
|
||||||
nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()')
|
it('matches when closing any tab', function()
|
||||||
repeat
|
nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()')
|
||||||
nvim('command', 'tabnew')
|
repeat
|
||||||
until nvim('eval', 'tabpagenr()') == 6 -- current tab is now 6
|
nvim('command', 'tabnew')
|
||||||
eq("\ntabclosed:6:6:5", nvim('command_output', 'tabclose')) -- close last 6, current tab is now 5
|
until nvim('eval', 'tabpagenr()') == 6 -- current tab is now 6
|
||||||
eq("\ntabclosed:5:5:4", nvim('command_output', 'close')) -- close last window on tab, closes tab
|
eq("\ntabclosed:6:6:5", nvim('command_output', 'tabclose')) -- close last 6, current tab is now 5
|
||||||
eq("\ntabclosed:2:2:3", nvim('command_output', '2tabclose')) -- close tab 2, current tab is now 3
|
eq("\ntabclosed:5:5:4", nvim('command_output', 'close')) -- close last window on tab, closes tab
|
||||||
eq("\ntabclosed:1:1:2\ntabclosed:1:1:1", nvim('command_output', 'tabonly')) -- close tabs 1 and 2
|
eq("\ntabclosed:2:2:3", nvim('command_output', '2tabclose')) -- close tab 2, current tab is now 3
|
||||||
end)
|
eq("\ntabclosed:1:1:2\ntabclosed:1:1:1", nvim('command_output', 'tabonly')) -- close tabs 1 and 2
|
||||||
end)
|
end)
|
||||||
describe('with NR as <afile>', function()
|
|
||||||
it('matches when closing a tab whose index is NR', function()
|
it('is triggered when closing a window via bdelete from another tab', function()
|
||||||
nvim('command', 'au! TabClosed 2 echom "tabclosed:match"')
|
nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()')
|
||||||
repeat
|
nvim('command', '1tabedit Xtestfile')
|
||||||
nvim('command', 'tabnew')
|
nvim('command', '1tabedit Xtestfile')
|
||||||
until nvim('eval', 'tabpagenr()') == 5 -- current tab is now 5
|
nvim('command', 'normal! 1gt')
|
||||||
-- sanity check, we shouldn't match on tabs with numbers other than 2
|
eq({1, 3}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
|
||||||
eq("\ntabclosed:5:5:4", nvim('command_output', 'tabclose'))
|
eq("\ntabclosed:2:2:1\ntabclosed:2:2:1", nvim('command_output', 'bdelete Xtestfile'))
|
||||||
-- close tab page 2, current tab is now 3
|
eq({1, 1}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
|
||||||
eq("\ntabclosed:2:2:3\ntabclosed:match", nvim('command_output', '2tabclose'))
|
end)
|
||||||
end)
|
|
||||||
end)
|
it('is triggered when closing a window via bdelete from current tab', function()
|
||||||
|
nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()')
|
||||||
|
nvim('command', 'file Xtestfile1')
|
||||||
|
nvim('command', '1tabedit Xtestfile2')
|
||||||
|
nvim('command', '1tabedit Xtestfile2')
|
||||||
|
|
||||||
|
-- Only one tab is closed, and the alternate file is used for the other.
|
||||||
|
eq({2, 3}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
|
||||||
|
eq("\ntabclosed:2:2:2", nvim('command_output', 'bdelete Xtestfile2'))
|
||||||
|
eq('Xtestfile1', nvim('eval', 'bufname("")'))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('with NR as <afile>', function()
|
||||||
|
it('matches when closing a tab whose index is NR', function()
|
||||||
|
nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()')
|
||||||
|
nvim('command', 'au! TabClosed 2 echom "tabclosed:match"')
|
||||||
|
repeat
|
||||||
|
nvim('command', 'tabnew')
|
||||||
|
until nvim('eval', 'tabpagenr()') == 7 -- current tab is now 7
|
||||||
|
-- sanity check, we shouldn't match on tabs with numbers other than 2
|
||||||
|
eq("\ntabclosed:7:7:6", nvim('command_output', 'tabclose'))
|
||||||
|
-- close tab page 2, current tab is now 5
|
||||||
|
eq("\ntabclosed:2:2:5\ntabclosed:match", nvim('command_output', '2tabclose'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
describe('with close', function()
|
||||||
|
it('is triggered', function()
|
||||||
|
nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()')
|
||||||
|
nvim('command', 'tabedit Xtestfile')
|
||||||
|
eq({2, 2}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
|
||||||
|
eq("\ntabclosed:2:2:1", nvim('command_output', 'close'))
|
||||||
|
eq({1, 1}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user