mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 14:58:18 +00:00
vim-patch:8.0.1274: setbufline() fails when using folding
Problem: setbufline() fails when using folding.
Solution: Set "curwin" if needed. (Ozaki Kiichi, closes vim/vim#2293)
0c4dc88a63
This commit is contained in:
@@ -14851,7 +14851,8 @@ static void set_buffer_lines(buf_T *buf, linenr_T lnum, typval_T *lines,
|
||||
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
|
||||
@@ -14862,8 +14863,19 @@ static void set_buffer_lines(buf_T *buf, linenr_T lnum, typval_T *lines,
|
||||
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;
|
||||
|
||||
@@ -14926,7 +14938,10 @@ static void set_buffer_lines(buf_T *buf, linenr_T lnum, typval_T *lines,
|
||||
appended_lines_mark(lcount, added);
|
||||
}
|
||||
|
||||
curbuf = curbuf_save;
|
||||
if (!is_curbuf) {
|
||||
curbuf = curbuf_save;
|
||||
curwin = curwin_save;
|
||||
}
|
||||
}
|
||||
|
||||
/// "setbufline()" function
|
||||
|
@@ -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 == ''
|
||||
|
Reference in New Issue
Block a user