diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 23b4bf2984..fbe2eaa6e9 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2793,15 +2793,6 @@ static void do_autocmd_cmdlinechanged(int firstc) static int command_line_changed(CommandLineState *s) { - if (ccline.cmdpos != s->prev_cmdpos - || (s->prev_cmdbuff != NULL - && strncmp(s->prev_cmdbuff, ccline.cmdbuff, (size_t)s->prev_cmdpos) != 0)) { - // Trigger CmdlineChanged autocommands. - do_autocmd_cmdlinechanged(s->firstc > 0 ? s->firstc : '-'); - } - - may_trigger_cursormovedc(s); - const bool prev_cmdpreview = cmdpreview; if (s->firstc == ':' && current_sctx.sc_sid == 0 // only if interactive @@ -2823,6 +2814,15 @@ static int command_line_changed(CommandLineState *s) } } + if (ccline.cmdpos != s->prev_cmdpos + || (s->prev_cmdbuff != NULL + && strncmp(s->prev_cmdbuff, ccline.cmdbuff, (size_t)s->prev_cmdpos) != 0)) { + // Trigger CmdlineChanged autocommands. + do_autocmd_cmdlinechanged(s->firstc > 0 ? s->firstc : '-'); + } + + may_trigger_cursormovedc(s); + if (p_arshape && !p_tbidi) { // Always redraw the whole command line to fix shaping and // right-left typing. Not efficient, but it works. diff --git a/test/functional/ui/inccommand_user_spec.lua b/test/functional/ui/inccommand_user_spec.lua index 5d604d22d7..0bdb37c369 100644 --- a/test/functional/ui/inccommand_user_spec.lua +++ b/test/functional/ui/inccommand_user_spec.lua @@ -569,20 +569,51 @@ describe("'inccommand' for user commands", function() assert(screen._cursor.col < 12) end feed(':Test bazarb') - screen:expect({ - grid = [[ - Preview | - oh no, even more text | - will the text ever stop | - oh well | - did the text stop | - why won't it stop | - make the text stop | - | - {1:~ }|*8 - :Test barb^az | - ]], - }) + screen:expect([[ + Preview | + oh no, even more text | + will the text ever stop | + oh well | + did the text stop | + why won't it stop | + make the text stop | + | + {1:~ }|*8 + :Test barb^az | + ]]) + end) + + it('works when CmdlineChanged calls wildtrigger() #35246', function() + api.nvim_buf_set_text(0, 0, 0, 1, -1, { '' }) + exec_lua([[ + vim.api.nvim_create_user_command("Repro", function() end, { + nargs = '+', + preview = function(opts, ns, buf) + vim.api.nvim_buf_set_lines(0, 0, -1, true, { opts.args }) + return 2 + end + }) + ]]) + command([[autocmd CmdlineChanged [:/\?] call wildtrigger()]]) + command('set wildmode=noselect:lastused,full wildoptions=pum') + feed(':Repro ') + screen:expect([[ + | + {1:~ }|*15 + :Repro ^ | + ]]) + feed('a') + screen:expect([[ + a | + {1:~ }|*15 + :Repro a^ | + ]]) + feed('bc') + screen:expect([[ + abc | + {1:~ }|*15 + :Repro abc^ | + ]]) end) end)