diff options
author | bfredl <bjorn.linse@gmail.com> | 2023-09-16 10:27:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-16 10:27:45 +0200 |
commit | 2d2cf150e13016566567cb854bfdd45d7a84b06e (patch) | |
tree | b43a43cd7dfec2455795a63eb79bdf0aed78df45 | |
parent | be10d65bfafe056025ffffa2c1131712b9a493a5 (diff) | |
parent | a916523574135549865d698732a6c9eaae7c7811 (diff) | |
download | rneovim-2d2cf150e13016566567cb854bfdd45d7a84b06e.tar.gz rneovim-2d2cf150e13016566567cb854bfdd45d7a84b06e.tar.bz2 rneovim-2d2cf150e13016566567cb854bfdd45d7a84b06e.zip |
Merge pull request #25078 from glepnir/au
fix(float): don't trigger au event when enter is false
-rw-r--r-- | src/nvim/api/win_config.c | 3 | ||||
-rw-r--r-- | test/functional/ui/float_spec.lua | 40 |
2 files changed, 42 insertions, 1 deletions
diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 6a16d06fb7..63cf3bb701 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -193,7 +193,8 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(float_config) *config, E } // autocmds in win_enter or win_set_buf below may close the window if (win_valid(wp) && buffer > 0) { - win_set_buf(wp, buf, fconfig.noautocmd, err); + Boolean noautocmd = !enter || fconfig.noautocmd; + win_set_buf(wp, buf, noautocmd, err); } if (!win_valid(wp)) { api_set_error(err, kErrorTypeException, "Window was closed immediately"); diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 4e2cee391a..e37b3ccb5f 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -415,6 +415,46 @@ describe('float window', function() eq(winids, eval('winids')) end) + it("open does not trigger BufEnter #15300", function() + local res = exec_lua[[ + local times = {} + local buf = vim.api.nvim_create_buf(fasle, true) + vim.api.nvim_create_autocmd('BufEnter', { + callback = function(opt) + if opt.buf == buf then + times[#times + 1] = 1 + end + end + }) + local win_id + local fconfig = { + relative = 'editor', + row = 10, + col = 10, + width = 10, + height = 10, + } + --enter is false doesn't trigger + win_id = vim.api.nvim_open_win(buf, false, fconfig) + vim.api.nvim_win_close(win_id, true) + times[#times + 1] = #times == 0 and true or nil + + --enter is true trigger + win_id = vim.api.nvim_open_win(buf, true, fconfig) + vim.api.nvim_win_close(win_id, true) + times[#times + 1] = #times == 2 and true or nil + + --enter is true and fconfig.noautocmd is true doesn't trigger + fconfig.noautocmd = true + win_id = vim.api.nvim_open_win(buf, true, fconfig) + vim.api.nvim_win_close(win_id, true) + times[#times + 1] = #times == 2 and true or nil + + return times + ]] + eq({true, 1, true}, res) + end) + it('no crash with bufpos and non-existent window', function() command('new') local closed_win = meths.get_current_win().id |