mirror of
https://github.com/neovim/neovim.git
synced 2026-07-23 17:32:51 +00:00
Problem:
cmdwin (the `:q` cmdline buffer) has various limitations which require
special-casing all over the codebase.
Besides complicating the code, it also breaks async plugins if they try
to create buffers/windows after some work is done, if the user happens
to open cmdwin at the wrong the moment:
Lua callback: …/guh.nvim/lua/guh/util.lua:531:
E11: Invalid in command-line window; <CR> executes, CTRL-C quits
stack traceback:
[C]: in function 'nvim_buf_delete'
…/guh.nvim/lua/guh/util.lua:531: in function <…/guh.nvim/lua/guh/util.lua:526>
Solution:
Just say no to "inception". Reimplement cmdwin as a normal buffer+window.
All of the cmdwin contortions (in both core, and innocent plugins) exist
literally only to support "inception": recursive
cmdwin-in-cmdline-things, like `<c-r>=`, `/`, search-during-substitute,
`:input()`, etc. So we just won't support that (though I have
a potential plan for that later, which I call "modal parking lot").
The benefit is that plugins, and core, no longer have to care about
cmdwin.
BONUS:
- mouse-drag on vertical separators works (it only worked for
horizontal/statusline before)
- inccommand-in-cmdwin now works correctly, for free (thus don't need
#40077).
POTENTIAL FOLLOWUPS
- Drop `CHECK_CMDWIN` ("E11: Invalid in command-line window"), allow chaos.
- Unify `BUFLOCK_OK` / `LOCK_OK` ?
DESIGN:
- Eliminate lots of C globals, `EX_CMDWIN`, etc.
- `text_locked()` no longer reports true for cmdwin.
- cmdwin = a normal window with 'winfixbuf', 'bufhidden=wipe',
'buftype=nofile'. Invariants come from those options rather than
special cases throughout the codebase.
- `nv_record` for q:/q//q? calls Lua
`nlua_call_vimfn("vim._core.cmdwin", …)`. No `K_CMDWIN`
/ cmdline-reader detour.
- `cedit_key` (`c_CTRL-F`) schedules a deferred event that calls
`vim._core.cmdwin.open(type, content, pos)` and returns `Ctrl_C` so
the in-flight cmdline cancels. Reader state is not serialized; instead
the captured `(type, line, col)` is replayed via
`nvim_feedkeys(type..line.."<CR>", "nt", …)` after user confirms.
- On confirm/cancel: `<CR>` / `<C-C>` calls into Lua which closes the
window and re-feeds the cmdline.
BREAKING CHANGES:
- Expression-register cmdline (`<C-R>=` from insert-mode) no longer
supports cmdwin. Same applies to `input()` / `inputlist()` (already
covered by `text_locked`).
- Usage of cmdwin in macros/mappings will probably break (assuming they
ever worked).
80 lines
2.1 KiB
Lua
80 lines
2.1 KiB
Lua
local t = require('test.testutil')
|
|
local n = require('test.functional.testnvim')()
|
|
local Screen = require('test.functional.ui.screen')
|
|
|
|
local eq = t.eq
|
|
local dedent = t.dedent
|
|
local exec = n.exec
|
|
local feed = n.feed
|
|
local clear = n.clear
|
|
local command = n.command
|
|
local api = n.api
|
|
|
|
local cmdtest = function(cmd, prep, ret1)
|
|
describe(':' .. cmd, function()
|
|
before_each(function()
|
|
clear()
|
|
api.nvim_buf_set_lines(0, 0, 1, true, { 'foo', 'bar', 'baz' })
|
|
end)
|
|
|
|
local buffer_contents = function()
|
|
return api.nvim_buf_get_lines(0, 0, -1, false)
|
|
end
|
|
|
|
it(cmd .. 's' .. prep .. ' the current line by default', function()
|
|
command(cmd .. '\nabc\ndef')
|
|
eq(ret1, buffer_contents())
|
|
end)
|
|
-- Used to crash because this invokes history processing which uses
|
|
-- hist_char2type which after fdb68e35e4c729c7ed097d8ade1da29e5b3f4b31
|
|
-- crashed.
|
|
it(cmd .. 's' .. prep .. ' the current line by default when feeding', function()
|
|
feed(':' .. cmd .. '\nabc\ndef\n.\n')
|
|
eq(ret1, buffer_contents())
|
|
end)
|
|
end)
|
|
end
|
|
cmdtest('insert', ' before', { 'abc', 'def', 'foo', 'bar', 'baz' })
|
|
cmdtest('append', ' after', { 'foo', 'abc', 'def', 'bar', 'baz' })
|
|
cmdtest('change', '', { 'abc', 'def', 'bar', 'baz' })
|
|
|
|
describe('first line is redrawn correctly after :append/:insert in an empty buffer', function()
|
|
local screen
|
|
before_each(function()
|
|
clear()
|
|
screen = Screen.new(20, 8)
|
|
screen:set_default_attr_ids({
|
|
[1] = { bold = true, foreground = Screen.colors.Blue },
|
|
[2] = { bold = true, reverse = true },
|
|
})
|
|
end)
|
|
|
|
it('using :append', function()
|
|
exec(dedent([[
|
|
append
|
|
aaaaa
|
|
bbbbb
|
|
.]]))
|
|
screen:expect([[
|
|
aaaaa |
|
|
^bbbbb |
|
|
{1:~ }|*5
|
|
|
|
|
]])
|
|
end)
|
|
|
|
it('using :insert', function()
|
|
exec(dedent([[
|
|
insert
|
|
aaaaa
|
|
bbbbb
|
|
.]]))
|
|
screen:expect([[
|
|
aaaaa |
|
|
^bbbbb |
|
|
{1:~ }|*5
|
|
|
|
|
]])
|
|
end)
|
|
end)
|