0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

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.
This commit is contained in:
Bram Moolenaar
2021-02-09 20:02:55 +01:00
parent a853089479
commit 963ffa0a5a
3 changed files with 30 additions and 16 deletions

View File

@@ -500,24 +500,25 @@ f_deletebufline(typval_T *argvars, typval_T *rettv)
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 (lnum = first; lnum <= last; ++lnum)
ml_delete_flags(first, ML_DEL_MESSAGE);
for (lnum = first; lnum <= last; ++lnum) FOR_ALL_TAB_WINDOWS(tp, wp)
ml_delete_flags(first, ML_DEL_MESSAGE); if (wp->w_buffer == buf)
{
FOR_ALL_TAB_WINDOWS(tp, wp) if (wp->w_cursor.lnum > last)
if (wp->w_buffer == buf) wp->w_cursor.lnum -= count;
{ else if (wp->w_cursor.lnum> first)
if (wp->w_cursor.lnum > last) wp->w_cursor.lnum = first;
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) check_cursor_col();
wp->w_cursor.lnum = wp->w_buffer->b_ml.ml_line_count; deleted_lines_mark(first, count);
} }
check_cursor_col();
deleted_lines_mark(first, count);
if (!is_curbuf) if (!is_curbuf)
{ {

View File

@@ -186,6 +186,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()

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2489,
/**/ /**/
2488, 2488,
/**/ /**/