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

Code before:
---@param entries MsgHistory[]
---@param prev_cmd boolean
function M.msg_history_show(entries, prev_cmd)
  if #entries == 0 then
    return
  end

  if cmd_on_key then
    -- Dismiss a still expanded cmdline.
    api.nvim_feedkeys(vim.keycode('<CR>'), 'n', false)
  elseif prev_cmd then
    -- Showing output of previous command, clear in case still visible.
    M.msg_clear()
  end

  api.nvim_buf_set_lines(ui.bufs.pager, 0, -1, false, {})
  for i, entry in ipairs(entries) do
    M.show_msg('pager', entry[2], i == 1, entry[3], 0)
  end

  M.set_pos('pager')
end

--- Adjust visibility and dimensions of the message windows after certain events.
---
---@param type? 'cmd'|'dialog'|'msg'|'pager' Type of to be positioned window (nil for all).
function M.set_pos(type)
  local function win_set_pos(win)
    local cfg = { hide = false, relative = 'laststatus', col = 10000 }
    local texth = type and api.nvim_win_text_height(win, {}) or {}
    local top = { vim.opt.fcs:get().msgsep or ' ', 'MsgSeparator' }
    cfg.height = type == 'pager' and texth.all
      or type and math.min(texth.all, math.ceil(o.lines * 0.5))
    cfg.border = win ~= ui.wins.msg and { '', top, '', '', '', '', '', '' } or nil
    cfg.focusable = type == 'cmd' or nil
    cfg.row = (win == ui.wins.msg and 0 or 1) - ui.cmd.wmnumode
    cfg.row = cfg.row - ((win == ui.wins.pager and o.laststatus == 3) and 1 or 0)
    api.nvim_win_set_config(win, cfg)

    if type == 'cmd' and not cmd_on_key then
      -- Temporarily expand the cmdline, until next key press.
      local save_spill = M.virt.msg[M.virt.idx.spill][1]
      local spill = texth.all > cfg.height and (' [+%d]'):format(texth.all - cfg.height)
      M.virt.msg[M.virt.idx.spill][1] = spill and { 0, spill } or nil
      set_virttext('msg', 'cmd')
      M.virt.msg[M.virt.idx.spill][1] = save_spill
      cmd_on_key = vim.on_key(function(_, typed)
        typed = typed and fn.keytrans(typed)
        if not typed or typed == '<MouseMove>' then
          return
        end

Review comment (suggestion):
```suggestion
---@param tgt? 'cmd'|'dialog'|'msg'|'pager' Target window to be positioned (nil for all).
```

Code after:
---@param entries MsgHistory[]
---@param prev_cmd boolean
function M.msg_history_show(entries, prev_cmd)
  if #entries == 0 then
    return
  end

  if cmd_on_key then
    -- Dismiss a still expanded cmdline.
    api.nvim_feedkeys(vim.keycode('<CR>'), 'n', false)
  elseif prev_cmd then
    -- Showing output of previous command, clear in case still visible.
    M.msg_clear()
  end

  api.nvim_buf_set_lines(ui.bufs.pager, 0, -1, false, {})
  for i, entry in ipairs(entries) do
    M.show_msg('pager', entry[2], i == 1, entry[3], 0)
  end

  M.set_pos('pager')
end

--- Adjust visibility and dimensions of the message windows after certain events.
---
---@param tar? 'cmd'|'dialog'|'msg'|'pager' To be positioned window (nil for all).
function M.set_pos(tar)
  local function win_set_pos(win)
    local cfg = { hide = false, relative = 'laststatus', col = 10000 }
    local texth = tar and api.nvim_win_text_height(win, {}) or {}
    local top = { vim.opt.fcs:get().msgsep or ' ', 'MsgSeparator' }
    cfg.height = tar and math.min(texth.all, tar == 'pager' and 10000 or math.ceil(o.lines * 0.5))
    cfg.border = win ~= ui.wins.msg and { '', top, '', '', '', '', '', '' } or nil
    cfg.focusable = tar == 'cmd' or nil
    cfg.row = (win == ui.wins.msg and 0 or 1) - ui.cmd.wmnumode
    cfg.row = cfg.row - ((win == ui.wins.pager and o.laststatus == 3) and 1 or 0)
    local title = { 'f/d/j: screen/page/line down, b/u/k: up, <Esc>: stop paging', 'MsgSeparator' }
    cfg.title = tar == 'dialog' and cfg.height < texth.all and { title } or nil
    api.nvim_win_set_config(win, cfg)

    if tar == 'cmd' and not cmd_on_key then
      -- Temporarily expand the cmdline, until next key press.
      local save_spill = M.virt.msg[M.virt.idx.spill][1]
      local spill = texth.all > cfg.height and (' [+%d]'):format(texth.all - cfg.height)
      M.virt.msg[M.virt.idx.spill][1] = spill and { 0, spill } or nil
      set_virttext('msg', 'cmd')
      M.virt.msg[M.virt.idx.spill][1] = save_spill
      cmd_on_key = vim.on_key(function(_, typed)
        typed = typed and fn.keytrans(typed)
        if not typed or typed == '<MouseMove>' then
          return