mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
vim-patch:9.0.0841: deletebufline() does not always return 1 on failure (#20980)
Problem: deletebufline() does not always return 1 on failure.
Solution: Refactor the code to make it work more predictable. (closes vim/vim#11511)
7af3ee2b83
This commit is contained in:
@@ -1510,6 +1510,7 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, EvalFuncData fpt
|
||||
|
||||
buf_T *curbuf_save = NULL;
|
||||
win_T *curwin_save = NULL;
|
||||
// After this don't use "return", goto "cleanup"!
|
||||
if (!is_curbuf) {
|
||||
VIsual_active = false;
|
||||
curbuf_save = curbuf;
|
||||
@@ -1530,34 +1531,35 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, EvalFuncData fpt
|
||||
}
|
||||
|
||||
if (u_save(first - 1, last + 1) == FAIL) {
|
||||
rettv->vval.v_number = 1; // FAIL
|
||||
} 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 -= (linenr_T)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);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
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 -= (linenr_T)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);
|
||||
rettv->vval.v_number = 0; // OK
|
||||
|
||||
cleanup:
|
||||
if (!is_curbuf) {
|
||||
curbuf = curbuf_save;
|
||||
curwin = curwin_save;
|
||||
VIsual_active = save_VIsual_active;
|
||||
}
|
||||
rettv->vval.v_number = 0; // OK
|
||||
}
|
||||
|
||||
/// "did_filetype()" function
|
||||
|
@@ -239,4 +239,20 @@ func Test_setbufline_startup_nofile()
|
||||
call delete('Xresult')
|
||||
endfunc
|
||||
|
||||
" Test that setbufline(), appendbufline() and deletebufline() should fail and
|
||||
" return 1 when "textlock" is active.
|
||||
func Test_change_bufline_with_textlock()
|
||||
new
|
||||
inoremap <buffer> <expr> <F2> setbufline('', 1, '')
|
||||
call assert_fails("normal a\<F2>", 'E565:')
|
||||
call assert_equal('1', getline(1))
|
||||
inoremap <buffer> <expr> <F2> appendbufline('', 1, '')
|
||||
call assert_fails("normal a\<F2>", 'E565:')
|
||||
call assert_equal('11', getline(1))
|
||||
inoremap <buffer> <expr> <F2> deletebufline('', 1)
|
||||
call assert_fails("normal a\<F2>", 'E565:')
|
||||
call assert_equal('111', getline(1))
|
||||
bwipe!
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
Reference in New Issue
Block a user