vim-patch:8.2.2489: current buffer is wrong after deletebufline() fails

Problem:    current buffer is wrong after deletebufline() fails to delete a
            line in another buffer.
Solution:   Restore the current buffer.
963ffa0a5a
This commit is contained in:
Jan Edmund Lazo
2021-02-09 21:26:41 -05:00
parent 61aea004d7
commit be981112b8
2 changed files with 27 additions and 17 deletions

View File

@@ -1629,27 +1629,26 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if (u_save(first - 1, last + 1) == FAIL) { if (u_save(first - 1, last + 1) == FAIL) {
rettv->vval.v_number = 1; // FAIL rettv->vval.v_number = 1; // FAIL
return; } else {
} for (linenr_T lnum = first; lnum <= last; lnum++) {
ml_delete(first, true);
}
for (linenr_T lnum = first; lnum <= last; lnum++) { FOR_ALL_TAB_WINDOWS(tp, wp) {
ml_delete(first, true); if (wp->w_buffer == buf) {
} if (wp->w_cursor.lnum > last) {
wp->w_cursor.lnum -= count;
FOR_ALL_TAB_WINDOWS(tp, wp) { } else if (wp->w_cursor.lnum> first) {
if (wp->w_buffer == buf) { wp->w_cursor.lnum = first;
if (wp->w_cursor.lnum > last) { }
wp->w_cursor.lnum -= count; if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) {
} else if (wp->w_cursor.lnum> first) { wp->w_cursor.lnum = wp->w_buffer->b_ml.ml_line_count;
wp->w_cursor.lnum = first; }
}
if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) {
wp->w_cursor.lnum = wp->w_buffer->b_ml.ml_line_count;
} }
} }
check_cursor_col();
deleted_lines_mark(first, count);
} }
check_cursor_col();
deleted_lines_mark(first, count);
if (!is_curbuf) { if (!is_curbuf) {
curbuf = curbuf_save; curbuf = curbuf_save;

View File

@@ -112,6 +112,17 @@ func Test_deletebufline()
call assert_equal(0, deletebufline(b, 1)) call assert_equal(0, deletebufline(b, 1))
call assert_equal(['b', 'c'], getbufline(b, 1, 2)) call assert_equal(['b', 'c'], getbufline(b, 1, 2))
exe "bwipe! " . b exe "bwipe! " . b
edit XbufOne
let one = bufnr()
call setline(1, ['a', 'b', 'c'])
setlocal nomodifiable
split XbufTwo
let two = bufnr()
call assert_fails('call deletebufline(one, 1)', 'E21:')
call assert_equal(two, bufnr())
bwipe! XbufTwo
bwipe! XbufOne
endfunc endfunc
func Test_appendbufline_redraw() func Test_appendbufline_redraw()