diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2023-04-20 21:17:25 +0100 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2023-07-05 08:31:52 +0100 |
commit | 77118d0da8badc4135be430f4cbb15bc95bc760f (patch) | |
tree | e1168e881f49751b807524559720e5212661244e /test/functional/vimscript/api_functions_spec.lua | |
parent | b2e8c0df2062f765a4cf7d96379c5f0f19393dfd (diff) | |
download | rneovim-77118d0da8badc4135be430f4cbb15bc95bc760f.tar.gz rneovim-77118d0da8badc4135be430f4cbb15bc95bc760f.tar.bz2 rneovim-77118d0da8badc4135be430f4cbb15bc95bc760f.zip |
fix(api): use text_locked() to check textlock
Problem: some API functions that check textlock (usually those that can change
curwin or curbuf) can break the cmdwin.
Solution: make FUNC_API_CHECK_TEXTLOCK call text_locked() instead, which already
checks for textlock, cmdwin and `<expr>` status.
Add FUNC_API_TEXTLOCK_ALLOW_CMDWIN to allow such functions to be usable in the
cmdwin if they can work properly there; the opt-in nature of this attribute
should hopefully help mitigate future bugs.
Also fix a regression in #22634 that made functions checking textlock usable in
`<expr>` mappings, and rename FUNC_API_CHECK_TEXTLOCK to FUNC_API_TEXTLOCK.
Diffstat (limited to 'test/functional/vimscript/api_functions_spec.lua')
-rw-r--r-- | test/functional/vimscript/api_functions_spec.lua | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/test/functional/vimscript/api_functions_spec.lua b/test/functional/vimscript/api_functions_spec.lua index 14678a966d..683ae2446c 100644 --- a/test/functional/vimscript/api_functions_spec.lua +++ b/test/functional/vimscript/api_functions_spec.lua @@ -7,6 +7,7 @@ local exc_exec, expect, eval = helpers.exc_exec, helpers.expect, helpers.eval local insert, pcall_err = helpers.insert, helpers.pcall_err local matches = helpers.matches local meths = helpers.meths +local feed = helpers.feed describe('eval-API', function() before_each(clear) @@ -48,10 +49,25 @@ describe('eval-API', function() eq('Vim(call):E5555: API call: Invalid buffer id: 17', err) end) - it('cannot change texts if textlocked', function() + it('cannot change text or window if textlocked', function() command("autocmd TextYankPost <buffer> ++once call nvim_buf_set_lines(0, 0, -1, v:false, [])") matches('Vim%(call%):E5555: API call: E565: Not allowed to change text or change window$', pcall_err(command, "normal! yy")) + + -- Functions checking textlock should also not be usable from <expr> mappings. + command("inoremap <expr> <f2> nvim_win_close(0, 1)") + eq('Vim(normal):E5555: API call: E565: Not allowed to change text or change window', + pcall_err(command, [[execute "normal i\<f2>"]])) + + -- Some functions checking textlock (usually those that may change the current window or buffer) + -- also ought to not be usable in the cmdwin. + feed("q:") + eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits', + pcall_err(meths.win_hide, 0)) + + -- But others, like nvim_buf_set_lines(), which just changes text, is OK. + curbufmeths.set_lines(0, -1, 1, {"wow!"}) + eq({'wow!'}, curbufmeths.get_lines(0, -1, 1)) end) it("use buffer numbers and windows ids as handles", function() |