]> granicus.if.org Git - vim/commitdiff
patch 8.0.1836: buffer-local window options may not be recent v8.0.1836
authorBram Moolenaar <Bram@vim.org>
Sun, 13 May 2018 16:05:33 +0000 (18:05 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 13 May 2018 16:05:33 +0000 (18:05 +0200)
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)

src/buffer.c
src/testdir/test_options.vim
src/version.c

index dd618337ef5bcb7aab486286f7678f9bca4bd874..e3cbdac1e8581f448198f85ff32469ba3b9b1d53 100644 (file)
@@ -2895,8 +2895,23 @@ get_winopts(buf_T *buf)
 #endif
 
     wip = find_wininfo(buf, TRUE);
-    if (wip != NULL && wip->wi_optset)
+    if (wip != NULL && wip->wi_win != NULL
+           && wip->wi_win != curwin && wip->wi_win->w_buffer == buf)
     {
+       /* The buffer is currently displayed in the window: use the actual
+        * option values instead of the saved (possibly outdated) values. */
+       win_T *wp = wip->wi_win;
+
+       copy_winopt(&wp->w_onebuf_opt, &curwin->w_onebuf_opt);
+#ifdef FEAT_FOLDING
+       curwin->w_fold_manual = wp->w_fold_manual;
+       curwin->w_foldinvalid = TRUE;
+       cloneFoldGrowArray(&wp->w_folds, &curwin->w_folds);
+#endif
+    }
+    else if (wip != NULL && wip->wi_optset)
+    {
+       /* the buffer was displayed in the current window earlier */
        copy_winopt(&wip->wi_opt, &curwin->w_onebuf_opt);
 #ifdef FEAT_FOLDING
        curwin->w_fold_manual = wip->wi_fold_manual;
index 8fa5f8b7bffd0b24fec6467aca8266674289395e..167cb1ce069b3d9db41cec4572e00d9f3942605f 100644 (file)
@@ -348,3 +348,55 @@ func Test_backupskip()
     endif
   endfor
 endfunc
+
+func Test_copy_winopt()
+    set hidden
+
+    " Test copy option from current buffer in window
+    split
+    enew
+    setlocal numberwidth=5
+    wincmd w
+    call assert_equal(4,&numberwidth)
+    bnext
+    call assert_equal(5,&numberwidth)
+    bw!
+    call assert_equal(4,&numberwidth)
+
+    " Test copy value from window that used to be display the buffer
+    split
+    enew
+    setlocal numberwidth=6
+    bnext
+    wincmd w
+    call assert_equal(4,&numberwidth)
+    bnext
+    call assert_equal(6,&numberwidth)
+    bw!
+
+    " Test that if buffer is current, don't use the stale cached value
+    " from the last time the buffer was displayed.
+    split
+    enew
+    setlocal numberwidth=7
+    bnext
+    bnext
+    setlocal numberwidth=8
+    wincmd w
+    call assert_equal(4,&numberwidth)
+    bnext
+    call assert_equal(8,&numberwidth)
+    bw!
+
+    " Test value is not copied if window already has seen the buffer
+    enew
+    split
+    setlocal numberwidth=9
+    bnext
+    setlocal numberwidth=10
+    wincmd w
+    call assert_equal(4,&numberwidth)
+    bnext
+    call assert_equal(4,&numberwidth)
+    bw!
+endfunc
index 417fc7c1c65d19af67d67accf963fe15a40615ad..feffa38f23f7f00386ea52b963ceb3098b8b7bd0 100644 (file)
@@ -761,6 +761,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1836,
 /**/
     1835,
 /**/