Skip to content

Commit 816968d

Browse files
committed
patch 8.0.1160: getting tab-local variable fails after closing window
Problem: Getting tab-local variable fails after closing window. Solution: set tp_firstwin and tp_lastwin. (Jason Franklin, closes #2170)
1 parent d371bbe commit 816968d

4 files changed

Lines changed: 28 additions & 9 deletions

File tree

src/evalfunc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5183,8 +5183,8 @@ f_gettabvar(typval_T *argvars, typval_T *rettv)
51835183
/* Set tp to be our tabpage, temporarily. Also set the window to the
51845184
* first window in the tabpage, otherwise the window is not valid. */
51855185
if (switch_win(&oldcurwin, &oldtabpage,
5186-
tp->tp_firstwin == NULL ? firstwin : tp->tp_firstwin, tp, TRUE)
5187-
== OK)
5186+
tp == curtab || tp->tp_firstwin == NULL ? firstwin
5187+
: tp->tp_firstwin, tp, TRUE) == OK)
51885188
{
51895189
/* look up the variable */
51905190
/* Let gettabvar({nr}, "") return the "t:" dictionary. */

src/testdir/test_getvar.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,19 @@ func Test_var()
8686
call assert_equal(1, gettabwinvar(2, 3, '&nux', 1))
8787
tabonly
8888
endfunc
89+
90+
" It was discovered that "gettabvar()" would fail if called from within the
91+
" tabline when the user closed a window. This test confirms the fix.
92+
func Test_gettabvar_in_tabline()
93+
let t:var_str = 'value'
94+
95+
set tabline=%{assert_equal('value',gettabvar(1,'var_str'))}
96+
set showtabline=2
97+
98+
" Simulate the user opening a split (which becomes window #1) and then
99+
" closing the split, which triggers the redrawing of the tabline.
100+
leftabove split
101+
redrawstatus!
102+
close
103+
redrawstatus!
104+
endfunc

src/version.c

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

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1160,
764766
/**/
765767
1159,
766768
/**/

src/window.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4775,13 +4775,14 @@ win_remove(
47754775
if (wp->w_prev != NULL)
47764776
wp->w_prev->w_next = wp->w_next;
47774777
else if (tp == NULL)
4778-
firstwin = wp->w_next;
4778+
firstwin = curtab->tp_firstwin = wp->w_next;
47794779
else
47804780
tp->tp_firstwin = wp->w_next;
4781+
47814782
if (wp->w_next != NULL)
47824783
wp->w_next->w_prev = wp->w_prev;
47834784
else if (tp == NULL)
4784-
lastwin = wp->w_prev;
4785+
lastwin = curtab->tp_lastwin = wp->w_prev;
47854786
else
47864787
tp->tp_lastwin = wp->w_prev;
47874788
}
@@ -6597,11 +6598,11 @@ restore_snapshot_rec(frame_T *sn, frame_T *fr)
65976598
*/
65986599
int
65996600
switch_win(
6600-
win_T **save_curwin UNUSED,
6601-
tabpage_T **save_curtab UNUSED,
6602-
win_T *win UNUSED,
6603-
tabpage_T *tp UNUSED,
6604-
int no_display UNUSED)
6601+
win_T **save_curwin,
6602+
tabpage_T **save_curtab,
6603+
win_T *win,
6604+
tabpage_T *tp,
6605+
int no_display)
66056606
{
66066607
# ifdef FEAT_AUTOCMD
66076608
block_autocmds();

0 commit comments

Comments
 (0)