fix(messages): avoid empty msg_showmode with 'noshowmode'

This commit is contained in:
Luuk van Baal
2025-01-22 23:13:40 +01:00
committed by luukvbaal
parent 0fd4ef5da7
commit d98827b634
3 changed files with 55 additions and 36 deletions

View File

@@ -3183,7 +3183,11 @@ void msg_ext_flush_showmode(void)
{ {
// Showmode messages doesn't interrupt normal message flow, so we use // Showmode messages doesn't interrupt normal message flow, so we use
// separate event. Still reuse the same chunking logic, for simplicity. // separate event. Still reuse the same chunking logic, for simplicity.
if (ui_has(kUIMessages)) { // This is called unconditionally; check if we are emitting, or have
// emitted non-empty "content".
static bool clear = false;
if (ui_has(kUIMessages) && (msg_ext_last_attr != -1 || clear)) {
clear = msg_ext_last_attr != -1;
msg_ext_emit_chunk(); msg_ext_emit_chunk();
Array *tofree = msg_ext_init_chunks(); Array *tofree = msg_ext_init_chunks();
ui_call_msg_showmode(*tofree); ui_call_msg_showmode(*tofree);

View File

@@ -345,31 +345,36 @@ describe('vim.ui_attach', function()
vim.api.nvim_buf_set_lines(0, -2, -1, false, { err[1] }) vim.api.nvim_buf_set_lines(0, -2, -1, false, { err[1] })
end) end)
]]) ]])
local s1 = [[
^ |
{1:~ }|*4
]]
screen:expect(s1)
feed('QQQQQQ<CR>')
screen:expect({ screen:expect({
grid = [[ grid = [[
^ | {9:obal 'err' (a nil value)} |
{1:~ }|*4 {9:stack traceback:} |
]], {9: [string "<nvim>"]:2: in function}|
}) {9: <[string "<nvim>"]:1>} |
feed('ifoo')
screen:expect({
grid = [[
foo^ |
{1:~ }|*4
]],
showmode = { { '-- INSERT --', 5, 11 } },
})
feed('<esc>:1mes clear<cr>:mes<cr>')
screen:expect({
grid = [[
foo |
{3: }|
{9:Excessive errors in vim.ui_attach() call}|
{9:back from ns: 1.} |
{100:Press ENTER or type command to continue}^ | {100:Press ENTER or type command to continue}^ |
]], ]],
cmdline = { { abort = false } }, messages = {
{
content = { { 'Press ENTER or type command to continue', 100, 18 } },
history = true,
kind = 'return_prompt',
},
},
}) })
feed(':1mes clear<CR>:mes<CR>')
screen:expect([[
|
{3: }|
{9:Excessive errors in vim.ui_attach() call}|
{9:back from ns: 1.} |
{100:Press ENTER or type command to continue}^ |
]])
feed('<cr>') feed('<cr>')
-- Also when scheduled -- Also when scheduled
exec_lua([[ exec_lua([[
@@ -378,7 +383,7 @@ describe('vim.ui_attach', function()
end) end)
]]) ]])
screen:expect({ screen:expect({
any = 'fo^o', grid = s1,
messages = { messages = {
{ {
content = { content = {
@@ -410,14 +415,12 @@ describe('vim.ui_attach', function()
}, },
}) })
feed('<esc>:1mes clear<cr>:mes<cr>') feed('<esc>:1mes clear<cr>:mes<cr>')
screen:expect({ screen:expect([[
grid = [[ |
foo | {3: }|
{3: }| {9:Excessive errors in vim.ui_attach() call}|
{9:Excessive errors in vim.ui_attach() call}| {9:back from ns: 2.} |
{9:back from ns: 2.} | {100:Press ENTER or type command to continue}^ |
{100:Press ENTER or type command to continue}^ | ]])
]],
})
end) end)
end) end)

View File

@@ -1391,13 +1391,25 @@ stack traceback:
screen_showmode(...) screen_showmode(...)
showmode = showmode + 1 showmode = showmode + 1
end end
local s1 = [[
^ |
{1:~ }|*4
]]
screen:expect(s1)
eq(showmode, 0)
feed('i')
screen:expect({ screen:expect({
grid = [[ grid = s1,
^ | showmode = { { '-- INSERT --', 5, 11 } },
{1:~ }|*4
]],
}) })
eq(showmode, 1) eq(showmode, 2)
command('set noshowmode')
feed('<Esc>')
screen:expect(s1)
eq(showmode, 3)
feed('i')
screen:expect_unchanged()
eq(showmode, 3)
end) end)
it('emits single message for multiline print())', function() it('emits single message for multiline print())', function()