diff options
author | Bram Moolenaar <Bram@vim.org> | 2017-11-06 21:32:54 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2017-11-06 21:32:54 +0100 |
commit | 0c4dc88a637a5027209aa00226996af84e248636 (patch) | |
tree | 7935c3de02676ecab304e13573e55559879bc0fe | |
parent | 4148be468f82eb4bf463be3610b00a132aee4186 (diff) | |
download | vim-0c4dc88a637a5027209aa00226996af84e248636.zip |
patch 8.0.1274: setbufline() fails when using folding
Problem: setbufline() fails when using folding.
Solution: Set "curwin" if needed. (Ozaki Kiichi, closes #2293)
-rw-r--r-- | src/evalfunc.c | 27 | ||||
-rw-r--r-- | src/testdir/test_bufline.vim | 26 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 51 insertions, 4 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c index 25536af2e..5e22fe4bc 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -9891,7 +9891,8 @@ set_buffer_lines(buf_T *buf, linenr_T lnum, typval_T *lines, typval_T *rettv) 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 lnum, typval_T *lines, typval_T *rettv) 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 lnum, typval_T *lines, typval_T *rettv) if (added > 0) appended_lines_mark(lcount, added); - curbuf = curbuf_save; + if (!is_curbuf) + { + curbuf = curbuf_save; + curwin = curwin_save; + } } /* diff --git a/src/testdir/test_bufline.vim b/src/testdir/test_bufline.vim index cc5c10e98..b886e9950 100644 --- a/src/testdir/test_bufline.vim +++ b/src/testdir/test_bufline.vim @@ -27,6 +27,32 @@ func Test_setbufline_getbufline() exe "bwipe! " . b endfunc +func Test_setbufline_getbufline_fold() + split Xtest + setlocal foldmethod=expr foldexpr=0 + let b = bufnr('%') + new + call assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) + call assert_equal(['foo'], getbufline(b, 1)) + call assert_equal(['bar'], getbufline(b, 2)) + call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) + exe "bwipe!" b + bwipe! +endfunc + +func Test_setbufline_getbufline_fold_tab() + split Xtest + setlocal foldmethod=expr foldexpr=0 + let b = bufnr('%') + tab new + call assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) + call assert_equal(['foo'], getbufline(b, 1)) + call assert_equal(['bar'], getbufline(b, 2)) + call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) + exe "bwipe!" b + bwipe! +endfunc + func Test_setline_startup() let cmd = GetVimCommand('Xscript') if cmd == '' diff --git a/src/version.c b/src/version.c index e47aad0da..7f519fbe8 100644 --- a/src/version.c +++ b/src/version.c @@ -762,6 +762,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1274, +/**/ 1273, /**/ 1272, |