aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2021-02-09 21:26:41 -0500
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2021-02-10 17:54:24 -0500
commitbe981112b8949506d05d6e38f23cd8976b8133c6 (patch)
treea1d756122816e2dc82c1dc24afc8186c7ad6d8c1
parent61aea004d7101e138794a337c03ef00a6b3994e6 (diff)
downloadrneovim-be981112b8949506d05d6e38f23cd8976b8133c6.tar.gz
rneovim-be981112b8949506d05d6e38f23cd8976b8133c6.tar.bz2
rneovim-be981112b8949506d05d6e38f23cd8976b8133c6.zip
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. https://github.com/vim/vim/commit/963ffa0a5a6091655ed72b4590ec5d5a1653bce8
-rw-r--r--src/nvim/eval/funcs.c33
-rw-r--r--src/nvim/testdir/test_bufline.vim11
2 files changed, 27 insertions, 17 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index fae5711b9c..3cc71a39f6 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -1629,27 +1629,26 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if (u_save(first - 1, last + 1) == FAIL) {
rettv->vval.v_number = 1; // FAIL
- return;
- }
-
- for (linenr_T lnum = first; lnum <= last; lnum++) {
- ml_delete(first, true);
- }
+ } else {
+ for (linenr_T lnum = first; lnum <= last; lnum++) {
+ ml_delete(first, true);
+ }
- 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;
+ 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);
}
- check_cursor_col();
- deleted_lines_mark(first, count);
if (!is_curbuf) {
curbuf = curbuf_save;
diff --git a/src/nvim/testdir/test_bufline.vim b/src/nvim/testdir/test_bufline.vim
index 076f03fdd8..e038bce08e 100644
--- a/src/nvim/testdir/test_bufline.vim
+++ b/src/nvim/testdir/test_bufline.vim
@@ -112,6 +112,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()