From d16bd456a8307158181a2aa659e5b78772f98cc5 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Fri, 22 May 2026 21:16:16 +0200 Subject: [PATCH] fix(cmdline): encode no prompt in cmdline_show.hl_id Problem: Unable to distinguish an empty prompt from no prompt in cmdline_show event. Solution: Set cmdline_show.hl_id to -1 when no prompt is active. --- runtime/doc/api-ui-events.txt | 43 +++++++++++++++++++---------------- runtime/doc/news.txt | 4 ++-- src/nvim/ex_getln.c | 4 ++-- test/functional/ui/screen.lua | 2 +- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/runtime/doc/api-ui-events.txt b/runtime/doc/api-ui-events.txt index 917af97951..8ac1b0cf08 100644 --- a/runtime/doc/api-ui-events.txt +++ b/runtime/doc/api-ui-events.txt @@ -767,27 +767,32 @@ This UI extension delegates presentation of the |cmdline| (except 'wildmenu'). For command-line 'wildmenu' UI events, activate |ui-popupmenu|. ["cmdline_show", content, pos, firstc, prompt, indent, level, hl_id] ~ - content: List of [attrs, string, hl_id] - [[{}, "t", hl_id], [attrs, "est", hl_id], ...] - Triggered when the cmdline is displayed or changed. - The `content` is the full content that should be displayed in the - cmdline, and the `pos` is the position of the cursor that in the - cmdline. The content is divided into chunks with different highlight - attributes represented as a dict (see |ui-event-highlight_set|). - `firstc` and `prompt` are text, that if non-empty should be - displayed in front of the command line. `firstc` always indicates - built-in command lines such as `:` (ex command) and `/` `?` (search), - while `prompt` is an |input()| prompt, highlighted with `hl_id`. - `indent` tells how many spaces the content should be indented. + content + Array of `[attr_id, text_chunk, hl_id]` tuples, building up the + cmdline text of chunks with different highlights. - The Nvim command line can be invoked recursively, for instance by - typing `=` at the command line prompt. The `level` field is used - to distinguish different command lines active at the same time. The - first invoked command line has level 1, the next recursively-invoked - prompt has level 2. A command line invoked from the |cmdline-window| - has a higher level than the edited command line. + pos + Position of the cursor in the cmdline (byte offset). + + firstc + Character preceding the cmdline content (|getcmdtype()|). + + prompt + String preceding the cmdline content when an |input()| prompt is + active, false otherwise. Highlighted with `hl_id`. + + indent + Number of spaces the content should be indented. + + level + Number indicating the cmdline recursion level. Incremented by + e.g |c_CTRL-R_=|, prompts or a commandline invoked from the + |cmdline-window|. + + hl_id + Highlight group ID of the prompt, -1 with no active prompt. ["cmdline_pos", pos, level] ~ Change the cursor position in the cmdline. @@ -878,7 +883,7 @@ must handle. content Array of `[attr_id, text_chunk, hl_id]` tuples, building up the - message text of chunks of different highlights. No extra spacing + message text of chunks with different highlights. No extra spacing should be added between chunks, the `text_chunk` by itself contains any necessary whitespace. Messages can contain line breaks "\n". diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index c6e596079f..87b3ea9d1c 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -69,8 +69,6 @@ API • |nvim_create_autocmd()|, |nvim_exec_autocmds()| and |nvim_clear_autocmds()| no longer treat an empty non-nil pattern as nil. • |nvim_clear_autocmds()| no longer treats an empty array event as nil. -• |ui-messages| `msg_show.bufwrite` and `msg_show.completion` messages are now - `msg_show.progress` events. DIAGNOSTICS @@ -90,6 +88,8 @@ EVENTS • |BufModifiedSet| has been removed. Use the |OptionSet| event with pattern "modified" instead. +• |ui-messages| `msg_show.bufwrite` and `msg_show.completion` messages are now + `msg_show.progress` events. LSP diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index ee79cd803f..dbbec988ce 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3673,8 +3673,8 @@ static void ui_ext_cmdline_show(CmdlineInfo *line) char charbuf[2] = { (char)line->cmdfirstc, 0 }; ui_call_cmdline_show(content, line->cmdpos, cstr_as_string(charbuf), - cstr_as_string((line->cmdprompt)), - line->cmdindent, line->level, line->hl_id); + cstr_as_string(line->cmdprompt), + line->cmdindent, line->level, line->cmdprompt ? line->hl_id : -1); if (line->special_char) { charbuf[0] = line->special_char; ui_call_cmdline_special_char(cstr_as_string(charbuf), diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 3c6e1034d7..ed2f733566 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -1390,7 +1390,7 @@ function Screen:_handle_cmdline_show(content, pos, firstc, prompt, indent, level if firstc == '' then firstc = nil end - if prompt == '' then + if hl_id == -1 then prompt = nil end if indent == 0 then