From 4ef217e272c463896b73ba726b0a498c497413a0 Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Wed, 25 Feb 2026 19:21:30 +0100 Subject: [PATCH] fix(ui2): leftover empty lines in msg window #38059 Problem: Timer removing a message from the msg buffer does not remove empty lines if window is closed (col([ui.wins.msg]) fails). Solution: Use nvim_buf_get_text() to check if line is empty. --- runtime/lua/vim/_core/ui2/messages.lua | 2 +- test/functional/ui/messages2_spec.lua | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/runtime/lua/vim/_core/ui2/messages.lua b/runtime/lua/vim/_core/ui2/messages.lua index cb260517fe..e4a6311db7 100644 --- a/runtime/lua/vim/_core/ui2/messages.lua +++ b/runtime/lua/vim/_core/ui2/messages.lua @@ -67,7 +67,7 @@ function M.msg:start_timer(buf, id) -- Remove message (including potentially leftover empty line). api.nvim_buf_set_text(buf, mark[1], mark[2], mark[3].end_row, mark[3].end_col, {}) - if fn.col({ mark[1] + 1, '$' }, ui.wins.msg) == 1 then + if api.nvim_buf_get_lines(ui.bufs.msg, mark[1], mark[1] + 1, false)[1] == '' then api.nvim_buf_set_lines(buf, mark[1], mark[1] + 1, false, {}) end diff --git a/test/functional/ui/messages2_spec.lua b/test/functional/ui/messages2_spec.lua index 498bbdf386..79de40dfa2 100644 --- a/test/functional/ui/messages2_spec.lua +++ b/test/functional/ui/messages2_spec.lua @@ -6,9 +6,10 @@ local Screen = require('test.functional.ui.screen') local clear, command, exec_lua, feed = n.clear, n.command, n.exec_lua, n.feed +local msg_timeout = 200 local function set_msg_target_zero_ch() exec_lua(function() - require('vim._core.ui2').enable({ msg = { target = 'msg' } }) + require('vim._core.ui2').enable({ msg = { target = 'msg', timeout = msg_timeout } }) vim.o.cmdheight = 0 end) end @@ -768,4 +769,24 @@ describe('messages2', function() {1:~ }|*13 ]]) end) + + it('closed msg window timer removes empty lines', function() + set_msg_target_zero_ch() + command('echo "foo" | echo "bar\n"') + screen:expect([[ + ^ | + {1:~ }|*10 + {1:~ }{4:foo}| + {1:~ }{4:bar}| + {1:~ }{4: }| + ]]) + command('fclose!') + screen:sleep(msg_timeout + 50) + command('echo "baz"') + screen:expect([[ + ^ | + {1:~ }|*12 + {1:~ }{4:baz}| + ]]) + end) end)