mirror of
https://github.com/neovim/neovim.git
synced 2026-07-23 09:23:09 +00:00
Problem:
Executing :messages while in cmdwin fails:
Error in "msg_history_show" UI event handler (ns=nvim.ui2):
Lua: …/_core/ui2/messages.lua:699: Invalid 'height': expected positive Integer
stack traceback:
[C]: in function 'nvim_win_set_config'
…/_core/ui2/messages.lua:699: in function 'set_pos'
…/_core/ui2/messages.lua:329: in function 'set_target_pos'
…/_core/ui2/messages.lua:389: in function 'show_msg'
…/_core/ui2/messages.lua:553: in function 'handler'
…/_core/ui2.lua:161: in function 'ui_callback'
…/_core/ui2.lua:210: in function <…/_core/ui2.lua:202>
The bug: when `texth.all` is small (e.g. 0 from a hidden pager whose new
content isn't laid out yet), or when the available height after
subtracting the cmdwin is small, `math.min(min, …)` can yield 0, and
`nvim_win_set_config` rejects `height=0`.
Solution:
Floor at 1.
123 lines
3.7 KiB
Lua
123 lines
3.7 KiB
Lua
-- Tests for non-blocking cmdwin. #40312
|
|
|
|
local t = require('test.testutil')
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
local feed = n.feed
|
|
local api = n.api
|
|
local fn = n.fn
|
|
local exec_lua = n.exec_lua
|
|
local eq = t.eq
|
|
|
|
describe('cmdwin', function()
|
|
before_each(n.clear)
|
|
|
|
it('q: opens cmdwin', function()
|
|
feed('q:')
|
|
eq(':', fn.getcmdwintype())
|
|
eq('[Command Line]', vim.fs.basename(api.nvim_buf_get_name(0)))
|
|
-- cmdwin-char is shown in window-local 'statuscolumn'.
|
|
eq('%#NonText#: ', api.nvim_get_option_value('statuscolumn', { win = 0 }))
|
|
|
|
eq('nofile', api.nvim_get_option_value('buftype', { buf = 0 }))
|
|
eq('wipe', api.nvim_get_option_value('bufhidden', { buf = 0 }))
|
|
eq(false, api.nvim_get_option_value('swapfile', { buf = 0 }))
|
|
eq(true, api.nvim_get_option_value('winfixbuf', { win = 0 }))
|
|
|
|
-- <CR> executes the cmdline
|
|
feed('ilet g:cmdwin_result = 42<Esc>')
|
|
feed('<CR>')
|
|
eq(42, api.nvim_get_var('cmdwin_result'))
|
|
eq('', fn.getcmdwintype())
|
|
end)
|
|
|
|
it('q/ opens cmdwin with search history', function()
|
|
feed('q/')
|
|
eq('/', fn.getcmdwintype())
|
|
end)
|
|
|
|
it('c_CTRL-F opens cmdwin pre-filled with current cmdline', function()
|
|
feed(':echo "hi"<C-F>')
|
|
n.poke_eventloop()
|
|
eq(':', fn.getcmdwintype())
|
|
eq('echo "hi"', api.nvim_get_current_line())
|
|
end)
|
|
|
|
it('history entry with literal newline char', function()
|
|
fn.histadd(':', 'echo \n x')
|
|
feed('q:')
|
|
eq(':', fn.getcmdwintype())
|
|
eq('echo \0 x', api.nvim_buf_get_lines(0, 0, 1, false)[1])
|
|
end)
|
|
|
|
it('<C-C> in normal mode cancels without executing', function()
|
|
feed('q:')
|
|
feed('iecho "nope"<Esc>')
|
|
feed('<C-C>')
|
|
eq('', fn.getcmdwintype())
|
|
-- v:errmsg should not contain a successful echo from the cancelled line.
|
|
end)
|
|
|
|
it('async API calls work while cmdwin is open #40312', function()
|
|
feed('q:')
|
|
eq(':', fn.getcmdwintype())
|
|
local ok, err = pcall(function()
|
|
local b = api.nvim_create_buf(true, false)
|
|
api.nvim_buf_delete(b, { force = true })
|
|
end)
|
|
eq(true, ok, 'buf_delete unexpectedly failed: ' .. tostring(err))
|
|
end)
|
|
|
|
it('textlock does not include cmdwin #40312', function()
|
|
feed('q:')
|
|
-- Setting an option from API used to fail with E11 in cmdwin.
|
|
api.nvim_set_option_value('wildignore', '*.tmp', {})
|
|
end)
|
|
|
|
it('E1292 cannot nest cmdwin', function()
|
|
feed('q:')
|
|
eq(':', fn.getcmdwintype())
|
|
feed('q:')
|
|
-- Still just one cmdwin.
|
|
eq(':', fn.getcmdwintype())
|
|
local nwin = 0
|
|
for _, w in ipairs(api.nvim_list_wins()) do
|
|
if api.nvim_get_option_value('winfixbuf', { win = w }) then
|
|
nwin = nwin + 1
|
|
end
|
|
end
|
|
eq(1, nwin)
|
|
end)
|
|
|
|
it(':quit closes cmdwin', function()
|
|
feed('q:')
|
|
eq(':', fn.getcmdwintype())
|
|
feed(':q<CR>')
|
|
eq('', fn.getcmdwintype())
|
|
end)
|
|
|
|
it(':messages from inside cmdwin works #40312', function()
|
|
-- Before #40312, this raised E11 because text_locked() returned true for cmdwin.
|
|
exec_lua([[vim.api.nvim_echo({{'hello from history'}}, true, {})]])
|
|
feed('q:')
|
|
eq(':', fn.getcmdwintype())
|
|
n.command('messages') -- Previously E11; now actually runs.
|
|
end)
|
|
|
|
it('CmdwinEnter/CmdwinLeave events', function()
|
|
exec_lua([[
|
|
_G.events = {}
|
|
vim.api.nvim_create_autocmd('CmdwinEnter', {
|
|
callback = function(a) table.insert(_G.events, 'enter:'..a.match) end,
|
|
})
|
|
vim.api.nvim_create_autocmd('CmdwinLeave', {
|
|
callback = function(a) table.insert(_G.events, 'leave:'..a.match) end,
|
|
})
|
|
]])
|
|
feed('q:')
|
|
n.poke_eventloop() -- Ensure q: is processed before the <C-C> mapping fires.
|
|
feed('<C-C>')
|
|
eq({ 'enter::', 'leave::' }, exec_lua('return _G.events'))
|
|
end)
|
|
end)
|