fix(startup): trigger UIEnter for the correct channel (#25860)

This commit is contained in:
zeertzjq 2023-11-01 12:16:37 +08:00 committed by GitHub
parent 4e6096a67f
commit d7359a8742
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 23 deletions

View File

@ -2570,6 +2570,9 @@ void do_autocmd_uienter(uint64_t chanid, bool attached)
{ {
static bool recursive = false; static bool recursive = false;
if (starting == NO_SCREEN) {
return; // user config hasn't been sourced yet
}
if (recursive) { if (recursive) {
return; // disallow recursion return; // disallow recursion
} }

View File

@ -589,7 +589,7 @@ int main(int argc, char **argv)
apply_autocmds(EVENT_VIMENTER, NULL, NULL, false, curbuf); apply_autocmds(EVENT_VIMENTER, NULL, NULL, false, curbuf);
TIME_MSG("VimEnter autocommands"); TIME_MSG("VimEnter autocommands");
if (use_remote_ui) { if (use_remote_ui) {
do_autocmd_uienter(CHAN_STDIO, true); do_autocmd_uienter_all();
TIME_MSG("UIEnter autocommands"); TIME_MSG("UIEnter autocommands");
} }

View File

@ -337,6 +337,16 @@ void vim_beep(unsigned val)
} }
} }
/// Trigger UIEnter for all attached UIs.
/// Used on startup after VimEnter.
void do_autocmd_uienter_all(void)
{
for (size_t i = 0; i < ui_count; i++) {
UIData *data = uis[i]->data;
do_autocmd_uienter(data->channel_id, true);
}
}
void ui_attach_impl(UI *ui, uint64_t chanid) void ui_attach_impl(UI *ui, uint64_t chanid)
{ {
if (ui_count == MAX_UI_COUNT) { if (ui_count == MAX_UI_COUNT) {

View File

@ -60,14 +60,13 @@ describe('nvim_ui_attach()', function()
end) end)
it('autocmds UIEnter/UILeave', function() it('autocmds UIEnter/UILeave', function()
clear{ clear{args_rm={'--headless'}}
args_rm={'--headless'}, exec([[
args={ let g:evs = []
'--cmd', 'let g:evs = []', autocmd UIEnter * call add(g:evs, "UIEnter") | let g:uienter_ev = deepcopy(v:event)
'--cmd', 'autocmd UIEnter * :call add(g:evs, "UIEnter") | let g:uienter_ev = deepcopy(v:event)', autocmd UILeave * call add(g:evs, "UILeave") | let g:uileave_ev = deepcopy(v:event)
'--cmd', 'autocmd UILeave * :call add(g:evs, "UILeave") | let g:uileave_ev = deepcopy(v:event)', autocmd VimEnter * call add(g:evs, "VimEnter")
'--cmd', 'autocmd VimEnter * :call add(g:evs, "VimEnter")', ]])
}}
local screen = Screen.new() local screen = Screen.new()
screen:attach() screen:attach()
eq({chan=1}, eval('g:uienter_ev')) eq({chan=1}, eval('g:uienter_ev'))

View File

@ -159,19 +159,21 @@ describe('--embed --listen UI', function()
local child_session = helpers.connect(child_server) local child_session = helpers.connect(child_server)
local info_ok, apiinfo = child_session:request('nvim_get_api_info') local info_ok, api_info = child_session:request('nvim_get_api_info')
assert(info_ok) ok(info_ok)
assert(#apiinfo == 2) eq(2, #api_info)
ok(api_info[1] > 2, 'channel_id > 2', api_info[1])
child_session:request('nvim_exec2', [[ child_session:request('nvim_exec2', [[
let g:vim_entered=0 let g:evs = []
autocmd VimEnter * call execute("let g:vim_entered=1") autocmd UIEnter * call add(g:evs, $"UIEnter:{v:event.chan}")
autocmd VimEnter * call add(g:evs, "VimEnter")
]], {}) ]], {})
-- g:vim_entered shouldn't be set to 1 until after attach -- VimEnter and UIEnter shouldn't be triggered until after attach
local var_ok, var = child_session:request('nvim_get_var', 'vim_entered') local var_ok, var = child_session:request('nvim_get_var', 'evs')
assert(var_ok) ok(var_ok)
ok(var == 0) eq({}, var)
local child_screen = Screen.new(40, 6) local child_screen = Screen.new(40, 6)
child_screen:attach(nil, child_session) child_screen:attach(nil, child_session)
@ -186,10 +188,9 @@ describe('--embed --listen UI', function()
[1] = {foreground = Screen.colors.Blue, bold = true}; [1] = {foreground = Screen.colors.Blue, bold = true};
}} }}
-- g:vim_entered should now be set to 1 -- VimEnter and UIEnter should now be triggered
var_ok, var = child_session:request('nvim_get_var', 'vim_entered') var_ok, var = child_session:request('nvim_get_var', 'evs')
assert(var_ok) ok(var_ok)
ok(var == 1) eq({'VimEnter', ('UIEnter:%d'):format(api_info[1])}, var)
end) end)
end) end)