fix(messages): no trailing newline for inputlist, tselect, z= with ext_messages

Problem:  Various list commands end in a newline to go to a new line on
          the message grid for the prompt message, which is unwanted
          with ext_messages.
Solution: Don't emit a trailing newline with ext_messages for
          inputlist(), :tselect and z=.

Co-authored-by: Tomasz N <przepompownia@users.noreply.github.com>
This commit is contained in:
Luuk van Baal
2025-03-13 02:14:01 +01:00
committed by luukvbaal
parent 6e588519c8
commit 282f73f067
4 changed files with 28 additions and 28 deletions

View File

@@ -3563,16 +3563,19 @@ static void f_inputlist(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
msg_scroll = true; msg_scroll = true;
msg_clr_eos(); msg_clr_eos();
TV_LIST_ITER_CONST(argvars[0].vval.v_list, li, { list_T *l = argvars[0].vval.v_list;
TV_LIST_ITER_CONST(l, li, {
msg_puts(tv_get_string(TV_LIST_ITEM_TV(li))); msg_puts(tv_get_string(TV_LIST_ITEM_TV(li)));
if (!ui_has(kUIMessages) || TV_LIST_ITEM_NEXT(l, li) != NULL) {
msg_putchar('\n'); msg_putchar('\n');
}
}); });
// Ask for choice. // Ask for choice.
bool mouse_used = false; bool mouse_used = false;
int selected = prompt_for_input(NULL, 0, false, &mouse_used); int selected = prompt_for_input(NULL, 0, false, &mouse_used);
if (mouse_used) { if (mouse_used) {
selected = tv_list_len(argvars[0].vval.v_list) - (cmdline_row - mouse_row); selected = tv_list_len(l) - (cmdline_row - mouse_row);
} }
rettv->vval.v_number = selected; rettv->vval.v_number = selected;

View File

@@ -588,8 +588,10 @@ void spell_suggest(int count)
msg_advance(30); msg_advance(30);
msg_puts(IObuff); msg_puts(IObuff);
} }
if (!ui_has(kUIMessages) || i < sug.su_ga.ga_len - 1) {
msg_putchar('\n'); msg_putchar('\n');
} }
}
cmdmsg_rl = false; cmdmsg_rl = false;
msg_col = 0; msg_col = 0;

View File

@@ -961,7 +961,7 @@ static void print_tag_list(bool new_tag, bool use_tagstack, int num_matches, cha
break; break;
} }
} }
if (msg_col) { if (msg_col && (!ui_has(kUIMessages) || i < num_matches - 1)) {
msg_putchar('\n'); msg_putchar('\n');
} }
os_breakcheck(); os_breakcheck();

View File

@@ -382,10 +382,6 @@ describe('ui/ext_messages', function()
feed('<CR>') feed('<CR>')
n.add_builddir_to_rtp() n.add_builddir_to_rtp()
feed(':help<CR>:tselect<CR>') feed(':help<CR>:tselect<CR>')
local tagfile = t.paths.test_build_dir .. '/runtime/doc/help.txt'
if t.is_os('win') then
tagfile = tagfile:gsub('/', '\\')
end
screen:expect({ screen:expect({
grid = [[ grid = [[
^*help.txt* Nvim | ^*help.txt* Nvim |
@@ -402,22 +398,21 @@ describe('ui/ext_messages', function()
prompt = 'Type number and <Enter> (q or empty cancels): ', prompt = 'Type number and <Enter> (q or empty cancels): ',
}, },
}, },
messages = { -- Message depends on runtimepath, only test the static text...
{ condition = function()
content = { for _, msg in ipairs(screen.messages) do
{ ' # pri kind tag', 101, 23 }, eq(false, msg.history)
{ '\n ' }, eq('confirm', msg.kind)
{ 'file\n', 101, 23 }, eq({ 150, ' # pri kind tag', 23 }, msg.content[1])
{ '> 1 F ' }, eq({ 0, '\n ', 0 }, msg.content[2])
{ 'help.txt', 101, 23 }, eq({ 150, 'file\n', 23 }, msg.content[3])
{ ' \n ' }, eq({ 0, '> 1 F ', 0 }, msg.content[4])
{ tagfile, 18, 5 }, eq({ 150, 'help.txt', 23 }, msg.content[5])
{ '\n *help.txt*\n' }, eq({ 0, ' \n ', 0 }, msg.content[6])
}, eq({ 0, '\n *help.txt*', 0 }, msg.content[#msg.content])
history = false, end
kind = 'confirm', screen.messages = {}
}, end,
},
}) })
feed('<CR>:bd<CR>') feed('<CR>:bd<CR>')
@@ -1330,7 +1325,7 @@ stack traceback:
}, },
messages = { messages = {
{ {
content = { { 'Change "helllo" to:\n 1 "Hello"\n 2 "Hallo"\n 3 "Hullo"\n' } }, content = { { 'Change "helllo" to:\n 1 "Hello"\n 2 "Hallo"\n 3 "Hullo"' } },
history = false, history = false,
kind = 'confirm', kind = 'confirm',
}, },
@@ -1353,7 +1348,7 @@ stack traceback:
}, },
messages = { messages = {
{ {
content = { { 'Change "helllo" to:\n 1 "Hello"\n 2 "Hallo"\n 3 "Hullo"\n' } }, content = { { 'Change "helllo" to:\n 1 "Hello"\n 2 "Hallo"\n 3 "Hullo"' } },
history = false, history = false,
kind = 'confirm', kind = 'confirm',
}, },
@@ -1385,7 +1380,7 @@ stack traceback:
}, },
messages = { messages = {
{ {
content = { { 'input0\ninput1\n' } }, content = { { 'input0\ninput1' } },
history = false, history = false,
kind = 'confirm', kind = 'confirm',
}, },