feat(ui2): configure maximum window heights #38392

Problem:
- Window height is set dynamically to match the text height,
  making it difficult for the user to use a different height.
- Cmdwin is closed to enter the pager but still taken into
  account for the pager position, and not restored when
  the pager is closed.
- Dialog pager handler may unnecessarily consume <Esc>.

Solution:
- Add maximum height config fields for each of the UI2 windows,
  where a number smaller than one is a fraction of 'lines',
  absolute height otherwise (i.e. `cfg.msg.pager.height = 0.5`).
- If the cmdwin will be closed to enter the pager, don't try
  to position the pager above it. Re-enter the cmdwin when the
  pager is closed.
- Only add vim.on_key() handler for the dialog paging is actually
  possible.
This commit is contained in:
luukvbaal
2026-03-21 15:20:06 +01:00
committed by GitHub
parent 7a5e9ef0aa
commit fbac2e5edc
4 changed files with 163 additions and 67 deletions

View File

@@ -9,7 +9,7 @@ local api, clear, command, exec_lua, feed = n.api, n.clear, n.command, n.exec_lu
local msg_timeout = 200
local function set_msg_target_zero_ch()
exec_lua(function()
require('vim._core.ui2').enable({ msg = { target = 'msg', timeout = msg_timeout } })
require('vim._core.ui2').enable({ msg = { target = 'msg', msg = { timeout = msg_timeout } } })
vim.o.cmdheight = 0
end)
end
@@ -212,6 +212,51 @@ describe('messages2', function()
{3:[Pager] 1,1 Top}|
{16::}^ |
]])
-- Can enter pager from cmdwin.
feed('<Esc>qq:')
screen:expect([[
x |
{1:~ }|*3
─────────────────────────────────────────────────────|
{1::}echo "foo" | echo "bar\nbaz\n"->repeat(&lines) |
{1::}^ |
{1:~ }|*5
{3:[Command Line] 2,0-1 All}|
|
]])
feed(':messages<CR>')
screen:expect([[
{3: }|
^foo |
foo |*10
{3:[Pager] 1,1 Top}|
|
]])
-- Cmdwin is restored after pager is closed.
feed('q')
screen:expect([[
x |
{1:~ }|*3
─────────────────────────────────────────────────────|
{1::}echo "foo" | echo "bar\nbaz\n"->repeat(&lines) |
{1::}messages |
{1::}^ |
{1:~ }|*4
{3:[Command Line] 3,0-1 All}|
|
]])
-- Configured maximum height.
command('quit | lua require("vim._core.ui2").enable({msg = {pager = {height = 2 } } })')
command('messages')
screen:expect([[
x |
{1:~ }|*8
{3: }|
^foo |
foo |
{3:[Pager] 1,1 Top}|
|
]])
end)
it('new buffer, window and options after closing a buffer or switching tabpage', function()
@@ -435,6 +480,21 @@ describe('messages2', function()
it('paging prompt dialog #35191', function()
screen:try_resize(71, screen._height)
-- Don't consume <Esc> when paging is not necessary.
feed(':call confirm("Ok?")<CR>')
screen:expect([[
|
{1:~ }|*10
{3: }|
{6:Ok?} |
{6:[O]k: }^ |
]])
feed('<Esc>')
screen:expect([[
^ |
{1:~ }|*12
|
]])
local top = [[
|
{1:~ }|*4