diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2024-02-11 18:45:56 +0000 |
---|---|---|
committer | Sean Dewar <6256228+seandewar@users.noreply.github.com> | 2024-03-08 23:24:00 +0000 |
commit | e55a502ed413d2bc8954b5227acfb34c8689f979 (patch) | |
tree | f3f39b5ff58fc794c901eb29e2aa5414bddb7682 | |
parent | a873f33993ef84e3f954127038e559e1ac1cac43 (diff) | |
download | rneovim-e55a502ed413d2bc8954b5227acfb34c8689f979.tar.gz rneovim-e55a502ed413d2bc8954b5227acfb34c8689f979.tar.bz2 rneovim-e55a502ed413d2bc8954b5227acfb34c8689f979.zip |
fix(api): open_win fire Buf* events when !enter && !noautocmd if entered early
Problem: if switch_win{_noblock} fails to restore the old curwin after WinNew
(e.g: it was closed), wp will become the new curwin, but win_set_buf enter
events would still be blocked if !enter && !noautocmd.
Solution: fire them, as we've actually entered the new window.
Note: there's a problem of switch_win{_noblock} failing to restore the old
curwin, leaving us in wp without triggering WinEnter/WinLeave, but this affects
all callers of switch_win{_noblock} anyways. (It's also not clear how WinLeave
can be called if the old curwin was closed already).
-rw-r--r-- | src/nvim/api/win_config.c | 2 | ||||
-rw-r--r-- | test/functional/api/window_spec.lua | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 9d63a1997c..238ec5df1e 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -294,7 +294,7 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(win_config) *config, Err tp = win_find_tabpage(wp); } if (tp && buf != wp->w_buffer) { - const bool noautocmd = !enter || fconfig.noautocmd; + const bool noautocmd = curwin != wp || fconfig.noautocmd; win_set_buf(wp, buf, noautocmd, err); if (!noautocmd) { tp = win_find_tabpage(wp); diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 8966c3b086..e0cb66de41 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -1571,6 +1571,16 @@ describe('API/win', function() ) eq(false, eval('fired')) end) + + it('fires Buf* autocommands when `!enter` if window is entered via autocommands', function() + exec([[ + autocmd WinNew * ++once only! + let fired = v:false + autocmd BufEnter * ++once let fired = v:true + ]]) + api.nvim_open_win(api.nvim_create_buf(true, true), false, { split = 'left' }) + eq(true, eval('fired')) + end) end) describe('set_config', function() |