From f245c0218adc9ff3452660dff97e62cea8e9a411 Mon Sep 17 00:00:00 2001 From: butwerenotthereyet <58348703+butwerenotthereyet@users.noreply.github.com> Date: Mon, 20 Jan 2020 15:14:51 -0800 Subject: [PATCH] tabpage: "tabnext #" switches to previous tab #11734 --- src/nvim/ex_docmd.c | 2 ++ .../functional/autocmd/tabnewentered_spec.lua | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 6bda62594e..02bee838d5 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -4651,6 +4651,8 @@ static int get_tabpage_arg(exarg_T *eap) if (relative == 0) { if (STRCMP(p, "$") == 0) { tab_number = LAST_TAB_NR; + } else if (STRCMP(p, "#") == 0) { + tab_number = tabpage_index(lastused_tabpage); } else if (p == p_save || *p_save == '-' || *p != NUL || tab_number > LAST_TAB_NR) { // No numbers as argument. diff --git a/test/functional/autocmd/tabnewentered_spec.lua b/test/functional/autocmd/tabnewentered_spec.lua index 123dbd0824..dc2fd3e97d 100644 --- a/test/functional/autocmd/tabnewentered_spec.lua +++ b/test/functional/autocmd/tabnewentered_spec.lua @@ -97,6 +97,7 @@ describe('tabpage/previous', function() switches_to_previous_after_new_tab_creation_at_end('g')) it('switches to previous via g. after new tab creation at end', switches_to_previous_after_new_tab_creation_at_end('g')) it('switches to previous via . after new tab creation at end', switches_to_previous_after_new_tab_creation_at_end('')) + it('switches to previous via :tabn #. after new tab creation at end', switches_to_previous_after_new_tab_creation_at_end(':tabn #')) local function switches_to_previous_after_new_tab_creation_in_middle(characters) return function() @@ -140,6 +141,8 @@ describe('tabpage/previous', function() switches_to_previous_after_new_tab_creation_in_middle('g')) it('switches to previous via after new tab creation in middle', switches_to_previous_after_new_tab_creation_in_middle('')) + it('switches to previous via :tabn # after new tab creation in middle', + switches_to_previous_after_new_tab_creation_in_middle(':tabn #')) local function switches_to_previous_after_switching_to_next_tab(characters) return function() @@ -180,6 +183,8 @@ describe('tabpage/previous', function() switches_to_previous_after_switching_to_next_tab('g')) it('switches to previous via after switching to next tab', switches_to_previous_after_switching_to_next_tab('')) + it('switches to previous via :tabn # after switching to next tab', + switches_to_previous_after_switching_to_next_tab(':tabn #')) local function switches_to_previous_after_switching_to_last_tab(characters) return function() @@ -222,6 +227,8 @@ describe('tabpage/previous', function() switches_to_previous_after_switching_to_last_tab('g')) it('switches to previous after switching to last tab', switches_to_previous_after_switching_to_last_tab('')) + it('switches to previous after switching to last tab', + switches_to_previous_after_switching_to_last_tab(':tabn #')) local function switches_to_previous_after_switching_to_previous_tab(characters) return function() @@ -262,6 +269,8 @@ describe('tabpage/previous', function() switches_to_previous_after_switching_to_previous_tab('g')) it('switches to previous via after switching to previous tab', switches_to_previous_after_switching_to_previous_tab('')) + it('switches to previous via :tabn # after switching to previous tab', + switches_to_previous_after_switching_to_previous_tab(':tabn #')) local function switches_to_previous_after_switching_to_first_tab(characters) return function() @@ -304,6 +313,8 @@ describe('tabpage/previous', function() switches_to_previous_after_switching_to_first_tab('g')) it('switches to previous via after switching to first tab', switches_to_previous_after_switching_to_first_tab('')) + it('switches to previous via :tabn # after switching to first tab', + switches_to_previous_after_switching_to_first_tab(':tabn #')) local function switches_to_previous_after_numbered_tab_switch(characters) return function() @@ -344,6 +355,8 @@ describe('tabpage/previous', function() switches_to_previous_after_numbered_tab_switch('g')) it('switches to previous via after numbered tab switch', switches_to_previous_after_numbered_tab_switch('')) + it('switches to previous via :tabn # after numbered tab switch', + switches_to_previous_after_numbered_tab_switch(':tabn #')) local function switches_to_previous_after_switching_to_previous(characters1, characters2) return function() @@ -386,18 +399,32 @@ describe('tabpage/previous', function() switches_to_previous_after_switching_to_previous('g', 'g')) it('switches to previous via after switching to previous via g', switches_to_previous_after_switching_to_previous('g', '')) + it('switches to previous via :tabn # after switching to previous via g', + switches_to_previous_after_switching_to_previous('g', ':tabn #')) it('switches to previous via g after switching to previous via g', switches_to_previous_after_switching_to_previous('g', 'g')) it('switches to previous via g after switching to previous via g', switches_to_previous_after_switching_to_previous('g', 'g')) it('switches to previous via after switching to previous via g', switches_to_previous_after_switching_to_previous('g', '')) + it('switches to previous via :tabn # after switching to previous via g', + switches_to_previous_after_switching_to_previous('g', ':tabn #')) it('switches to previous via g after switching to previous via ', switches_to_previous_after_switching_to_previous('', 'g')) it('switches to previous via g after switching to previous via ', switches_to_previous_after_switching_to_previous('', 'g')) it('switches to previous via after switching to previous via ', switches_to_previous_after_switching_to_previous('', '')) + it('switches to previous via :tabn # after switching to previous via ', + switches_to_previous_after_switching_to_previous('', ':tabn #')) + it('switches to previous via g after switching to previous via :tabn #', + switches_to_previous_after_switching_to_previous(':tabn #', 'g')) + it('switches to previous via g after switching to previous via :tabn #', + switches_to_previous_after_switching_to_previous(':tabn #', 'g')) + it('switches to previous via after switching to previous via ', + switches_to_previous_after_switching_to_previous(':tabn #', '')) + it('switches to previous via :tabn # after switching to previous via :tabn #', + switches_to_previous_after_switching_to_previous(':tabn #', ':tabn #')) local function does_not_switch_to_previous_after_closing_current_tab(characters) return function() @@ -437,6 +464,8 @@ describe('tabpage/previous', function() does_not_switch_to_previous_after_closing_current_tab('g')) it('does not switch to previous via after closing current tab', does_not_switch_to_previous_after_closing_current_tab('')) + it('does not switch to previous via :tabn # after closing current tab', + does_not_switch_to_previous_after_closing_current_tab(':tabn #')) local function does_not_switch_to_previous_after_entering_operator_pending(characters) return function() @@ -480,6 +509,11 @@ describe('tabpage/previous', function() -- does_not_switch_to_previous_after_entering_operator_pending('g')) it('does not switch to previous via after entering operator pending', does_not_switch_to_previous_after_entering_operator_pending('')) + -- NOTE: When in operator pending mode, pressing : leaves operator pending + -- mode and enters command mode, so :tabn # does in fact switch + -- tabs. + -- it('does not switch to previous via :tabn # after entering operator pending', + -- does_not_switch_to_previous_after_entering_operator_pending(':tabn #')) local function cmdline_win_prevents_tab_switch(characters, completion_visible) return function() @@ -516,6 +550,8 @@ describe('tabpage/previous', function() cmdline_win_prevents_tab_switch('g', 1)) it('cmdline-win prevents tab switch via ', cmdline_win_prevents_tab_switch('', 0)) + it('cmdline-win prevents tab switch via :tabn #', + cmdline_win_prevents_tab_switch(':tabn #', 0)) it(':tabs indicates correct prevtab curwin', function() -- Add three tabs for a total of four