diff options
author | Sean Dewar <6256228+seandewar@users.noreply.github.com> | 2024-04-15 00:10:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-14 16:10:16 -0700 |
commit | 7180ef690180cf92d1d49811820c46dd60e4d1c6 (patch) | |
tree | fd3a3167aa497c37501075a7814820d9507d0e76 /test/functional/api/window_spec.lua | |
parent | e3fb937545f736ac33a783a0ef2bbe2927a68ef4 (diff) | |
download | rneovim-7180ef690180cf92d1d49811820c46dd60e4d1c6.tar.gz rneovim-7180ef690180cf92d1d49811820c46dd60e4d1c6.tar.bz2 rneovim-7180ef690180cf92d1d49811820c46dd60e4d1c6.zip |
feat(api)!: nvim_open_win: noautocmd blocks all autocmds #28192
Problem: noautocmd is confusing; despite its name, it doesn't block all
autocommands (instead it blocks only those related to setting the buffer), and
is commonly used by plugins to open windows while producing minimal
side-effects.
Solution: be consistent and block all autocommands when noautocmd is set.
This includes WinNew (again), plus autocommands from entering the window (if
enter is set) like WinEnter, WinLeave, TabEnter, .etc.
See the discussion at https://github.com/neovim/neovim/pull/14659#issuecomment-2040029517
for more information.
Remove win_set_buf's noautocmd argument, as it's no longer needed.
NOTE: pum_create_float_preview sets noautocmd for win_set_buf, but all its
callers already use block_autocmds.
Despite that, pum_create_float_preview doesn't actually properly handle
autocommands (it has no checks for whether those from win_enter or
nvim_create_buf free the window).
For now, ensure autocommands are blocked within it for correctness (in case it's
ever called outside of a block_autocmds context; the function seems to have been
refactored in #26739 anyway).
Diffstat (limited to 'test/functional/api/window_spec.lua')
-rw-r--r-- | test/functional/api/window_spec.lua | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 6a99352b3c..d9d3772df2 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -1162,27 +1162,6 @@ describe('API/win', function() end) describe('open_win', function() - it('noautocmd option works', function() - command('autocmd BufEnter,BufLeave,BufWinEnter * let g:fired = 1') - api.nvim_open_win(api.nvim_create_buf(true, true), true, { - relative = 'win', - row = 3, - col = 3, - width = 12, - height = 3, - noautocmd = true, - }) - eq(0, fn.exists('g:fired')) - api.nvim_open_win(api.nvim_create_buf(true, true), true, { - relative = 'win', - row = 3, - col = 3, - width = 12, - height = 3, - }) - eq(1, fn.exists('g:fired')) - end) - it('disallowed in cmdwin if enter=true or buf=cmdwin_buf', function() local new_buf = api.nvim_create_buf(true, true) feed('q:') @@ -1406,6 +1385,24 @@ describe('API/win', function() return info end + it('noautocmd option works', function() + local info = setup_tabbed_autocmd_test() + + api.nvim_open_win( + info.other_buf, + true, + { split = 'left', win = info.tab2_curwin, noautocmd = true } + ) + eq({}, eval('result')) + + api.nvim_open_win( + info.orig_buf, + true, + { relative = 'editor', row = 0, col = 0, width = 10, height = 10, noautocmd = true } + ) + eq({}, eval('result')) + end) + it('fires expected autocmds when creating splits without entering', function() local info = setup_tabbed_autocmd_test() |