Repository: neovim/neovim
File: runtime/lua/vim/_extui/messages.lua (Lua)

Code before:
    else
      M.box:start_timer(ext.bufs.box, row - start_row + 1)
    end
  elseif tar == 'cmd' and dupe == 0 then
    fn.clearmatches(ext.wins.cmd) -- Clear matchparen highlights.
    if ext.cmd.row > 0 then
      -- In block mode the cmdheight is already dynamic, so just print the full message
      -- regardless of height. Spoof cmdline_show to put cmdline below message.
      ext.cmd.row = ext.cmd.row + 1 + row - start_row
      ext.cmd.cmdline_show({}, 0, ':', '', ext.cmd.indent, 0, 0)
      api.nvim__redraw({ flush = true, cursor = true, win = ext.wins.cmd })
    else
      local h = api.nvim_win_text_height(ext.wins.cmd, {})
      if more and h.all > ext.cmdheight then
        ext.cmd.highlighter:destroy()
        msg_to_more(tar)
        return
      end

      api.nvim_win_set_cursor(ext.wins[tar], { 1, 0 })
      ext.cmd.highlighter.active[ext.bufs.cmd] = nil
      -- Place [+x] indicator for lines that spill over 'cmdheight'.
      M.cmd.lines, M.cmd.msg_row = h.all, h.end_row
      local spill = M.cmd.lines > ext.cmdheight and ('[+%d]'):format(M.cmd.lines - ext.cmdheight)
      M.virt.msg[M.virt.idx.spill][1] = spill and { 0, spill } or nil
    end
  end

  if M[tar] then
    -- Place (x) indicator for repeated messages. Mainly to mitigate unnecessary
    -- resizing of the message box window, but also placed in the cmdline.
    M.virt.msg[M.virt.idx.dupe][1] = dupe > 0 and { 0, ('(%d)'):format(dupe) } or nil
    M.prev_msg, M.dupe, M[tar].count = msg, dupe, count
    set_virttext('msg')
  end

  -- Reset message state the next event loop iteration.
  if start_row == 0 or ext.cmd.row > 0 then
    vim.schedule(function()
      col, M.cmd.lines, M.cmd.count = 0, 0, 0
    end)
  end
end

local replace_bufwrite = false
--- Route the message to the appropriate sink.
---
---@param kind string
---@alias MsgChunk [integer, string, integer]
---@alias MsgContent MsgChunk[]
---@param content MsgContent

Review comment (bug):
Is this a typo? `ext.wins.cmd` -> `ext.wins.pager`

Something broken with this:
```
nvim --clean --cmd "lua require('vim._extui').enable({})" +"com" --cmd "lua vim.defer_fn(function() vim.api.nvim_input('g<lt>w*') end, 100)"
```
```
Lua: /home/phan/b/neovim/runtime/lua/vim/_extui/messages.lua:96: Line index out of bounds
stack traceback:
               [C]: in function 'nvim_win_text_height'
               /home/phan/b/neovim/runtime/lua/vim/_extui/messages.lua:96: in function 'set_virttext'
               /home/phan/b/neovim/runtime/lua/vim/_extui/messages.lua:414: in function 'handler'
               /home/phan/b/neovim/runtime/lua/vim/_extui.lua:47: in function 'ui_callback'
               /home/phan/b/neovim/runtime/lua/vim/_extui.lua:82: in function </home/phan/b/neovim/runtime/lua/vim/_extui.lua:78>
```

Code after:
    local h = api.nvim_win_text_height(ext.wins.msg, { start_row = start_row })
    if pager and h.all > 1 then
      msg_to_pager(tar)
      return
    end

    M.set_pos('msg')
    M.msg.width = width
    if restart then
      M.msg.timer:stop()
      M.msg.timer:set_repeat(4000)
      M.msg.timer:again()
    else
      M.msg:start_timer(ext.bufs.msg, row - start_row + 1)
    end
  elseif tar == 'cmd' and dupe == 0 then
    fn.clearmatches(ext.wins.cmd) -- Clear matchparen highlights.
    if ext.cmd.row > 0 then
      -- In block mode the cmdheight is already dynamic, so just print the full message
      -- regardless of height. Spoof cmdline_show to put cmdline below message.
      ext.cmd.row = ext.cmd.row + 1 + row - start_row
      ext.cmd.cmdline_show({}, 0, ':', '', ext.cmd.indent, 0, 0)
      api.nvim__redraw({ flush = true, cursor = true, win = ext.wins.cmd })
    else
      local h = api.nvim_win_text_height(ext.wins.cmd, {})
      local want_pager = pager or will_pager or not api.nvim_win_get_config(ext.wins.pager).hide
      if want_pager and h.all > ext.cmdheight then
        msg_to_pager(tar)
        return
      end

      api.nvim_win_set_cursor(ext.wins[tar], { 1, 0 })
      ext.cmd.highlighter.active[ext.bufs.cmd] = nil
      -- Place [+x] indicator for lines that spill over 'cmdheight'.
      M.cmd.lines, M.cmd.msg_row = h.all, h.end_row
      local spill = M.cmd.lines > ext.cmdheight and ('[+%d]'):format(M.cmd.lines - ext.cmdheight)
      M.virt.msg[M.virt.idx.spill][1] = spill and { 0, spill } or nil
    end
  end

  if M[tar] then
    -- Place (x) indicator for repeated messages. Mainly to mitigate unnecessary
    -- resizing of the message window, but also placed in the cmdline.
    M.virt.msg[M.virt.idx.dupe][1] = dupe > 0 and { 0, ('(%d)'):format(dupe) } or nil
    M.prev_msg, M.dupe, M[tar].count = msg, dupe, count
    set_virttext('msg')
  end

  -- Reset message state the next event loop iteration.
  if start_row == 0 or ext.cmd.row > 0 then
    vim.schedule(function()