fix(ui): only internal messages are unsafe #37462

Problem:  Fast context for msg_show event inhibits vim.ui_attach from
          displaying a stream of messages from a single command.

Solution: Remove fast context from msg_show events emitted as a result
          of explicit API/command calls. The fast context was originally
          introduced to prevent issues with internal messages.
This commit is contained in:
luukvbaal
2026-01-27 00:18:51 +01:00
committed by GitHub
parent e9d03b92b6
commit d30d91f3a4
12 changed files with 215 additions and 140 deletions

View File

@@ -38,17 +38,19 @@ ext.msg = require('vim._extui.messages')
ext.cmd = require('vim._extui.cmdline')
local M = {}
local function ui_callback(event, ...)
local function ui_callback(redraw_msg, event, ...)
local handler = ext.msg[event] or ext.cmd[event]
ext.check_targets()
handler(...)
-- Cmdline mode and non-empty showcmd requires an immediate redraw.
if ext.cmd[event] or event == 'msg_showcmd' and select(1, ...)[1] then
-- Cmdline mode, non-fast message and non-empty showcmd require an immediate redraw.
if ext.cmd[event] or redraw_msg or (event == 'msg_showcmd' and select(1, ...)[1]) then
ext.redrawing = true
api.nvim__redraw({
flush = handler ~= ext.cmd.cmdline_hide or nil,
cursor = handler == ext.cmd[event] and true or nil,
win = handler == ext.cmd[event] and ext.wins.cmd or nil,
})
ext.redrawing = false
end
end
local scheduled_ui_callback = vim.schedule_wrap(ui_callback)
@@ -86,10 +88,11 @@ function M.enable(opts)
if not (ext.msg[event] or ext.cmd[event]) then
return
end
if vim.in_fast_event() then
scheduled_ui_callback(event, ...)
-- Ensure cmdline is placed after a scheduled message in block mode.
if vim.in_fast_event() or (event == 'cmdline_show' and ext.cmd.srow > 0) then
scheduled_ui_callback(false, event, ...)
else
ui_callback(event, ...)
ui_callback(event == 'msg_show', event, ...)
end
return true
end)