mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
fix(api): nvim_create_user_command addr option should allow ranges #35077
Problem: Using `addr` without `range` in nvim_create_user_command gives
"No range allowed" error, inconsistent with `:command -addr` behavior.
Solution: Set EX_RANGE flag when `addr` option is specified to match
`:command` behavior.
(cherry picked from commit 22df649210
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
41fa343484
commit
09b0003d38
@@ -1073,6 +1073,7 @@ void create_user_command(uint64_t channel_id, String name, Object command, Dict(
|
|||||||
goto err;
|
goto err;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
argt |= EX_RANGE;
|
||||||
if (addr_type_arg != ADDR_LINES) {
|
if (addr_type_arg != ADDR_LINES) {
|
||||||
argt |= EX_ZEROR;
|
argt |= EX_ZEROR;
|
||||||
}
|
}
|
||||||
|
@@ -782,6 +782,13 @@ describe('nvim_create_user_command', function()
|
|||||||
eq(5, #api.nvim_list_tabpages())
|
eq(5, #api.nvim_list_tabpages())
|
||||||
eq(1, fn.tabpagenr())
|
eq(1, fn.tabpagenr())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('"addr" flag allows ranges without explicit "range" flag', function()
|
||||||
|
exec_lua([[
|
||||||
|
vim.api.nvim_create_user_command('Test2', 'echo "hello <line1><line2>"', { addr = 'other' })
|
||||||
|
]])
|
||||||
|
eq('hello 12', n.exec_capture('1,2Test2'))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('nvim_del_user_command', function()
|
describe('nvim_del_user_command', function()
|
||||||
|
Reference in New Issue
Block a user