]> granicus.if.org Git - vim/commitdiff
patch 8.2.2489: current buffer is wrong after deletebufline() fails v8.2.2489
authorBram Moolenaar <Bram@vim.org>
Tue, 9 Feb 2021 19:02:55 +0000 (20:02 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 9 Feb 2021 19:02:55 +0000 (20:02 +0100)
Problem:    current buffer is wrong after deletebufline() fails to delete a
            line in another buffer.
Solution:   Restore the current buffer.

src/evalbuffer.c
src/testdir/test_bufline.vim
src/version.c

index 2ba2f679a5c7b4d58da10ceb5d3c33642621138a..b7aac9a6b113e1725ffb1016211d6a0ae2ffd25b 100644 (file)
@@ -500,24 +500,25 @@ f_deletebufline(typval_T *argvars, typval_T *rettv)
     if (u_save(first - 1, last + 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)
-       ml_delete_flags(first, ML_DEL_MESSAGE);
-
-    FOR_ALL_TAB_WINDOWS(tp, wp)
-       if (wp->w_buffer == buf)
-       {
-           if (wp->w_cursor.lnum > last)
-               wp->w_cursor.lnum -= count;
-           else if (wp->w_cursor.lnum> first)
-               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);
+       FOR_ALL_TAB_WINDOWS(tp, wp)
+           if (wp->w_buffer == buf)
+           {
+               if (wp->w_cursor.lnum > last)
+                   wp->w_cursor.lnum -= count;
+               else if (wp->w_cursor.lnum> first)
+                   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);
+    }
 
     if (!is_curbuf)
     {
index 5df528818400bba9f6b60ff5dee8830283cbc975..04653bacb84e0f50d12c33bd4488b410d2851319 100644 (file)
@@ -186,6 +186,17 @@ func Test_deletebufline()
   call assert_equal(0, deletebufline(b, 1))
   call assert_equal(['b', 'c'], getbufline(b, 1, 2))
   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
 
 func Test_appendbufline_redraw()
index 8b5de13e126067a038c607631db0bfc143ecf093..18f0b840fba0a8a94d16b0539b27360b24f2d414 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2489,
 /**/
     2488,
 /**/