neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 8fba428bc6f36ae038a9286517e15b33257a1359
parent 78a1e6bc0060eec1afa7de099c4cee35ca35527f
Author: Marco Hinz <mh.codebro@gmail.com>
Date:   Thu, 12 May 2022 16:43:20 +0200

fix(cmd): make :-tabmove work with modifiers (#18447)

`:tabmove` takes either an argument (`:tabmove -`) or an address (`:-tabmove`).

The code assumed that `:tabmove` is the first command on the cmdline, but that
is not the case when using additional modifiers like `:silent`.

Make the addr parsing more robust by searching the command first, then going
back to check for a potential address `-`.
Diffstat:
Msrc/nvim/ex_docmd.c | 4+++-
Mtest/functional/editor/tabpage_spec.lua | 11++++++++++-
2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c @@ -5248,7 +5248,9 @@ static int get_tabpage_arg(exarg_T *eap) tab_number = 0; } else { tab_number = (int)eap->line2; - if (!unaccept_arg0 && *skipwhite(*eap->cmdlinep) == '-') { + char *cmdp = eap->cmd; + while (--cmdp > *eap->cmdlinep && (*cmdp == ' ' || ascii_isdigit(*cmdp))) {} + if (!unaccept_arg0 && *cmdp == '-') { tab_number--; if (tab_number < unaccept_arg0) { eap->errmsg = e_invarg; diff --git a/test/functional/editor/tabpage_spec.lua b/test/functional/editor/tabpage_spec.lua @@ -7,6 +7,7 @@ local neq = helpers.neq local feed = helpers.feed local eval = helpers.eval local exec = helpers.exec +local funcs = helpers.funcs describe('tabpage', function() before_each(clear) @@ -51,5 +52,13 @@ describe('tabpage', function() ]]) neq(999, eval('g:win_closed')) end) -end) + it(":tabmove handles modifiers and addr", function() + command('tabnew | tabnew | tabnew') + eq(4, funcs.nvim_tabpage_get_number(0)) + command(' silent :keepalt :: ::: silent! - tabmove') + eq(3, funcs.nvim_tabpage_get_number(0)) + command(' silent :keepalt :: ::: silent! -2 tabmove') + eq(1, funcs.nvim_tabpage_get_number(0)) + end) +end)