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

Code before:
      border = border or nil,
      height = height,
      row = win == ext.wins.msg and 0 or 1,
      col = 10000,
    }

    if type == 'msg' then
      -- Ensure last line is visible and first line is at top of window.
      local row = (texth.all > height and texth.end_row or 0) + 1
      api.nvim_win_set_cursor(ext.wins.msg, { row, 0 })
    elseif type == 'pager' then
      if fn.getcmdwintype() ~= '' then
        if will_pager then
          config.relative, config.win, config.row, config.col = 'win', 0, 0, 0
        else
          -- Cannot leave the cmdwin to enter the pager, so close it.
          -- NOTE: regression w.r.t. the message grid, which allowed this.
          -- Resolving that would require somehow bypassing textlock for the pager.
          api.nvim_command('quit')
        end
      end

      routed = will_pager
      -- It's actually closed one event iteration later so schedule in case it was open.
      vim.schedule(function()
        -- For a routed message close the pager on the next typed mapping, unless entered.
        if routed then
          vim.on_key(function(_, typed)
            if typed then
              vim.schedule(function()
                if routed and api.nvim_win_is_valid(win) and api.nvim_get_current_win() ~= win then
                  api.nvim_win_set_config(win, { hide = true })
                end
              end)
            end
            vim.on_key(nil, ext.ns)
          end, ext.ns)
          return
        end

        -- When explicitly opened, enter and hide when window other than the cmdwin is entered.
        api.nvim_set_current_win(win)
        api.nvim_create_autocmd({ 'WinEnter', 'CmdwinEnter', 'CmdwinLeave' }, {
          callback = function(ev)
            -- Make pager relative to cmdwin when it is opened, restore when it is closed.
            config = ev.event == 'CmdwinLeave' and config
              or ev.event == 'WinEnter' and { hide = true }
              or { relative = 'win', win = 0, row = 0, col = 0 }
            if api.nvim_win_is_valid(win) then
              api.nvim_win_set_config(win, config)
            end

Review comment (suggestion):
```suggestion
        -- For a routed message close the pager on any user input (unless pager is focused).
```

Code after:
      border = border or nil,
      height = height,
      row = win == ext.wins.msg and 0 or 1,
      col = 10000,
    }

    if type == 'msg' then
      -- Ensure last line is visible and first line is at top of window.
      local row = (texth.all > height and texth.end_row or 0) + 1
      api.nvim_win_set_cursor(ext.wins.msg, { row, 0 })
    elseif type == 'pager' then
      if fn.getcmdwintype() ~= '' then
        if will_pager then
          config.relative, config.win, config.row, config.col = 'win', 0, 0, 0
        else
          -- Cannot leave the cmdwin to enter the pager, so close it.
          -- NOTE: regression w.r.t. the message grid, which allowed this.
          -- Resolving that would require somehow bypassing textlock for the pager.
          api.nvim_command('quit')
        end
      end

      routed = will_pager
      -- It's actually closed one event iteration later so schedule in case it was open.
      vim.schedule(function()
        -- For a routed message, hide pager on user input (unless that input focused the pager).
        if routed then
          vim.on_key(function(_, typed)
            if typed then
              vim.schedule(function()
                if routed and api.nvim_win_is_valid(win) and api.nvim_get_current_win() ~= win then
                  api.nvim_win_set_config(win, { hide = true })
                end
              end)
            end
            vim.on_key(nil, ext.ns)
          end, ext.ns)
          return
        end

        -- When explicitly opened, enter and hide when window other than the cmdwin is entered.
        api.nvim_set_current_win(win)
        api.nvim_create_autocmd({ 'WinEnter', 'CmdwinEnter', 'CmdwinLeave' }, {
          callback = function(ev)
            -- Make pager relative to cmdwin when it is opened, restore when it is closed.
            config = ev.event == 'CmdwinLeave' and config
              or ev.event == 'WinEnter' and { hide = true }
              or { relative = 'win', win = 0, row = 0, col = 0 }
            if api.nvim_win_is_valid(win) then
              api.nvim_win_set_config(win, config)
            end