Skip to content

Commit 8281a16

Browse files
committed
patch 9.0.1472: ":drop fname" may change the last used tab page
Problem: ":drop fname" may change the last used tab page. Solution: Restore the last used tab page when :drop has changed it. (closes #12087)
1 parent be9624e commit 8281a16

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/arglist.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,13 +1240,19 @@ do_arg_all(
12401240
need_mouse_correct = TRUE;
12411241
#endif
12421242

1243+
tabpage_T *new_lu_tp = curtab;
1244+
12431245
// Try closing all windows that are not in the argument list.
12441246
// Also close windows that are not full width;
12451247
// When 'hidden' or "forceit" set the buffer becomes hidden.
12461248
// Windows that have a changed buffer and can't be hidden won't be closed.
12471249
// When the ":tab" modifier was used do this for all tab pages.
12481250
arg_all_close_unused_windows(&aall);
12491251

1252+
// Now set the last used tabpage to where we started.
1253+
if (valid_tabpage(new_lu_tp))
1254+
lastused_tabpage = new_lu_tp;
1255+
12501256
// Open a window for files in the argument list that don't have one.
12511257
// ARGCOUNT may change while doing this, because of autocommands.
12521258
if (count > aall.opened_len || count <= 0)

src/testdir/test_tabpage.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,22 @@ function Test_tabpage()
150150
tabonly!
151151
endfunc
152152

153+
func Test_tabpage_drop()
154+
edit f1
155+
tab split f2
156+
tab split f3
157+
normal! gt
158+
call assert_equal(1, tabpagenr())
159+
160+
tab drop f3
161+
call assert_equal(3, tabpagenr())
162+
call assert_equal(1, tabpagenr('#'))
163+
bwipe!
164+
bwipe!
165+
bwipe!
166+
call assert_equal(1, tabpagenr('$'))
167+
endfunc
168+
153169
" Test autocommands
154170
function Test_tabpage_with_autocmd()
155171
command -nargs=1 -bar C :call add(s:li, '=== ' . <q-args> . ' ===')|<args>

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ static char *(features[]) =
695695

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1472,
698700
/**/
699701
1471,
700702
/**/

0 commit comments

Comments
 (0)