aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/window_spec.lua
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2024-02-04 00:42:36 +0000
committerSean Dewar <6256228+seandewar@users.noreply.github.com>2024-03-08 22:37:31 +0000
commitbcb70eeac48040fd6d6bfc20cf7fb6f41374a67c (patch)
treeda257682c06ca8f8f11b5c4aac8db49649d0cd1a /test/functional/api/window_spec.lua
parenta69c72063994f8e9064b6d9c9f280120423897b8 (diff)
downloadrneovim-bcb70eeac48040fd6d6bfc20cf7fb6f41374a67c.tar.gz
rneovim-bcb70eeac48040fd6d6bfc20cf7fb6f41374a67c.tar.bz2
rneovim-bcb70eeac48040fd6d6bfc20cf7fb6f41374a67c.zip
fix(api): win_set_config autocmds crash when moving win to other tabpage
Problem: win_enter autocommands can close new_curwin, crashing if it was the last window in its tabpage after removing win, or can close parent, crashing when attempting to split it later. Solution: remove win first, check that parent is valid after win_enter. NOTE: This isn't actually quite right, as this means win is not in the window list or even has a frame when triggering enter autocommands (so it's not considered valid in the tabpage). This is addressed in later commits.
Diffstat (limited to 'test/functional/api/window_spec.lua')
-rw-r--r--test/functional/api/window_spec.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua
index 097a546ef2..a812d502eb 100644
--- a/test/functional/api/window_spec.lua
+++ b/test/functional/api/window_spec.lua
@@ -1663,6 +1663,27 @@ describe('API/win', function()
},
}, fn.winlayout())
end)
+
+ it('closing new curwin when moving window to other tabpage works', function()
+ command('split | tabnew')
+ local w = api.nvim_get_current_win()
+ local t = api.nvim_get_current_tabpage()
+ command('tabfirst | autocmd WinEnter * ++once quit')
+ api.nvim_win_set_config(0, { win = w, split = 'left' })
+ -- New tabpage is now the only one, as WinEnter closed the new curwin in the original.
+ eq(t, api.nvim_get_current_tabpage())
+ eq({ t }, api.nvim_list_tabpages())
+ end)
+
+ it('closing split parent when moving window to other tabpage aborts', function()
+ command('split | tabnew')
+ local w = api.nvim_get_current_win()
+ command('tabfirst | autocmd WinEnter * call nvim_win_close(' .. w .. ', 1)')
+ eq(
+ 'Window to split was closed',
+ pcall_err(api.nvim_win_set_config, 0, { win = w, split = 'left' })
+ )
+ end)
end)
describe('get_config', function()