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.
This commit is contained in:
luukvbaal
2026-02-25 19:21:30 +01:00
committed by GitHub
parent c0f8b3fb66
commit 4ef217e272
2 changed files with 23 additions and 2 deletions

View File

@@ -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

View File

@@ -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)