diff src/evalfunc.c @ 12794:d4fc8a7dc7d9 v8.0.1274

patch 8.0.1274: setbufline() fails when using folding commit https://github.com/vim/vim/commit/0c4dc88a637a5027209aa00226996af84e248636 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Nov 6 21:32:54 2017 +0100 patch 8.0.1274: setbufline() fails when using folding Problem: setbufline() fails when using folding. Solution: Set "curwin" if needed. (Ozaki Kiichi, closes https://github.com/vim/vim/issues/2293)
author Christian Brabandt <cb@256bit.org>
date Mon, 06 Nov 2017 21:45:04 +0100
parents 7749260f261c
children 963cdeb42c41
line wrap: on
line diff
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -9891,7 +9891,8 @@ set_buffer_lines(buf_T *buf, linenr_T ln
     listitem_T	*li = NULL;
     long	added = 0;
     linenr_T	lcount;
-    buf_T	*curbuf_save;
+    buf_T	*curbuf_save = NULL;
+    win_T	*curwin_save = NULL;
     int		is_curbuf = buf == curbuf;
 
     /* When using the current buffer ml_mfp will be set if needed.  Useful when
@@ -9903,8 +9904,22 @@ set_buffer_lines(buf_T *buf, linenr_T ln
 	return;
     }
 
-    curbuf_save = curbuf;
-    curbuf = buf;
+    if (!is_curbuf)
+    {
+	wininfo_T *wip;
+
+	curbuf_save = curbuf;
+	curwin_save = curwin;
+	curbuf = buf;
+	for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next)
+	{
+	    if (wip->wi_win != NULL)
+	    {
+		curwin = wip->wi_win;
+		break;
+	    }
+	}
+    }
 
     lcount = curbuf->b_ml.ml_line_count;
 
@@ -9967,7 +9982,11 @@ set_buffer_lines(buf_T *buf, linenr_T ln
     if (added > 0)
 	appended_lines_mark(lcount, added);
 
-    curbuf = curbuf_save;
+    if (!is_curbuf)
+    {
+	curbuf = curbuf_save;
+	curwin = curwin_save;
+    }
 }
 
 /*