Skip to content

Commit 25782a7

Browse files
committed
patch 8.0.1836: buffer-local window options may not be recent
Problem: Buffer-local window options may not be recent if the buffer is still open in another window. Solution: Copy the options from the window instead of the outdated window options. (Bjorn Linse, closes #2336)
1 parent 2290b1f commit 25782a7

3 files changed

Lines changed: 70 additions & 1 deletion

File tree

src/buffer.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2895,8 +2895,23 @@ get_winopts(buf_T *buf)
28952895
#endif
28962896

28972897
wip = find_wininfo(buf, TRUE);
2898-
if (wip != NULL && wip->wi_optset)
2898+
if (wip != NULL && wip->wi_win != NULL
2899+
&& wip->wi_win != curwin && wip->wi_win->w_buffer == buf)
28992900
{
2901+
/* The buffer is currently displayed in the window: use the actual
2902+
* option values instead of the saved (possibly outdated) values. */
2903+
win_T *wp = wip->wi_win;
2904+
2905+
copy_winopt(&wp->w_onebuf_opt, &curwin->w_onebuf_opt);
2906+
#ifdef FEAT_FOLDING
2907+
curwin->w_fold_manual = wp->w_fold_manual;
2908+
curwin->w_foldinvalid = TRUE;
2909+
cloneFoldGrowArray(&wp->w_folds, &curwin->w_folds);
2910+
#endif
2911+
}
2912+
else if (wip != NULL && wip->wi_optset)
2913+
{
2914+
/* the buffer was displayed in the current window earlier */
29002915
copy_winopt(&wip->wi_opt, &curwin->w_onebuf_opt);
29012916
#ifdef FEAT_FOLDING
29022917
curwin->w_fold_manual = wip->wi_fold_manual;

src/testdir/test_options.vim

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,55 @@ func Test_backupskip()
348348
endif
349349
endfor
350350
endfunc
351+
352+
func Test_copy_winopt()
353+
set hidden
354+
355+
" Test copy option from current buffer in window
356+
split
357+
enew
358+
setlocal numberwidth=5
359+
wincmd w
360+
call assert_equal(4,&numberwidth)
361+
bnext
362+
call assert_equal(5,&numberwidth)
363+
bw!
364+
call assert_equal(4,&numberwidth)
365+
366+
" Test copy value from window that used to be display the buffer
367+
split
368+
enew
369+
setlocal numberwidth=6
370+
bnext
371+
wincmd w
372+
call assert_equal(4,&numberwidth)
373+
bnext
374+
call assert_equal(6,&numberwidth)
375+
bw!
376+
377+
" Test that if buffer is current, don't use the stale cached value
378+
" from the last time the buffer was displayed.
379+
split
380+
enew
381+
setlocal numberwidth=7
382+
bnext
383+
bnext
384+
setlocal numberwidth=8
385+
wincmd w
386+
call assert_equal(4,&numberwidth)
387+
bnext
388+
call assert_equal(8,&numberwidth)
389+
bw!
390+
391+
" Test value is not copied if window already has seen the buffer
392+
enew
393+
split
394+
setlocal numberwidth=9
395+
bnext
396+
setlocal numberwidth=10
397+
wincmd w
398+
call assert_equal(4,&numberwidth)
399+
bnext
400+
call assert_equal(4,&numberwidth)
401+
bw!
402+
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+
1836,
764766
/**/
765767
1835,
766768
/**/

0 commit comments

Comments
 (0)