From 437ed3cee2d29a24d555a873d024cd851b953153 Mon Sep 17 00:00:00 2001 From: glepnir Date: Mon, 11 Sep 2023 19:46:15 +0800 Subject: [PATCH] fix(float): trigger winnew event when float window create --- src/nvim/api/win_config.c | 3 +++ test/functional/ui/float_spec.lua | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 63cf3bb701..35b9e73d81 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -195,6 +195,9 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(float_config) *config, E if (win_valid(wp) && buffer > 0) { Boolean noautocmd = !enter || fconfig.noautocmd; win_set_buf(wp, buf, noautocmd, err); + if (!fconfig.noautocmd) { + apply_autocmds(EVENT_WINNEW, NULL, NULL, false, buf); + } } 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 e37b3ccb5f..556859478e 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -103,6 +103,29 @@ describe('float window', function() assert_alive() end) + it('open with WinNew autocmd', function() + local res = exec_lua([[ + local triggerd = false + local buf = vim.api.nvim_create_buf(true, true) + vim.api.nvim_create_autocmd('WinNew', { + callback = function(opt) + if opt.buf == buf then + triggerd = true + end + end + }) + local opts = { + relative = "win", + row = 0, col = 0, + width = 1, height = 1, + noautocmd = false, + } + vim.api.nvim_open_win(buf, true, opts) + return triggerd + ]]) + eq(true, res) + end) + it('opened with correct height', function() local height = exec_lua([[ vim.go.winheight = 20