From 664efa497e4e3d79d2e4ab486acbf1471b2389b0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 7 Jul 2022 04:47:18 +0800 Subject: vim-patch:8.2.0614: get ml_get error when deleting a line in 'completefunc' (#19244) Problem: Get ml_get error when deleting a line in 'completefunc'. (Yegappan Lakshmanan) Solution: Lock the text while evaluating 'completefunc'. https://github.com/vim/vim/commit/ff06f283e3e4b3ec43012dd3b83f8454c98f6639 Fix a mistake in the porting of patch 8.1.0098. Cherry-pick Test_run_excmd_with_text_locked() from patch 8.2.0270. Cherry-pick test_gf.vim changes from patch 8.2.0369. Cherry-pick message change from later patches. --- src/nvim/testdir/test_edit.vim | 20 ++++++++++++++++++-- src/nvim/testdir/test_ex_mode.vim | 8 ++++---- src/nvim/testdir/test_excmd.vim | 24 ++++++++++++++++++++++++ src/nvim/testdir/test_gf.vim | 15 +++++++++++++++ src/nvim/testdir/test_popup.vim | 10 ++++------ 5 files changed, 65 insertions(+), 12 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_edit.vim b/src/nvim/testdir/test_edit.vim index c14afbe5b9..19b088959b 100644 --- a/src/nvim/testdir/test_edit.vim +++ b/src/nvim/testdir/test_edit.vim @@ -985,6 +985,22 @@ func Test_edit_CTRL_U() bw! endfunc +func Test_edit_completefunc_delete() + func CompleteFunc(findstart, base) + if a:findstart == 1 + return col('.') - 1 + endif + normal dd + return ['a', 'b'] + endfunc + new + set completefunc=CompleteFunc + call setline(1, ['', 'abcd', '']) + 2d + call assert_fails("normal 2G$a\\", 'E565:') + bwipe! +endfunc + func Test_edit_CTRL_Z() " Ctrl-Z when insertmode is not set inserts it literally new @@ -1331,7 +1347,7 @@ func Test_edit_forbidden() try call feedkeys("ix\", 'tnix') call assert_fails(1, 'textlock') - catch /^Vim\%((\a\+)\)\=:E523/ " catch E523: not allowed here + catch /^Vim\%((\a\+)\)\=:E565/ " catch E565: not allowed here endtry " TODO: Might be a bug: should x really be inserted here call assert_equal(['xa'], getline(1, '$')) @@ -1356,7 +1372,7 @@ func Test_edit_forbidden() try call feedkeys("i\\\", 'tnix') call assert_fails(1, 'change in complete function') - catch /^Vim\%((\a\+)\)\=:E523/ " catch E523 + catch /^Vim\%((\a\+)\)\=:E565/ " catch E565 endtry delfu Complete set completefunc= diff --git a/src/nvim/testdir/test_ex_mode.vim b/src/nvim/testdir/test_ex_mode.vim index 0ce333fa40..c3f7fb45f4 100644 --- a/src/nvim/testdir/test_ex_mode.vim +++ b/src/nvim/testdir/test_ex_mode.vim @@ -67,13 +67,13 @@ endfunc func Test_ex_mode_errors() " Not allowed to enter ex mode when text is locked au InsertCharPre normal! gQ - let caught_e523 = 0 + let caught_e565 = 0 try call feedkeys("ix\", 'xt') - catch /^Vim\%((\a\+)\)\=:E523/ " catch E523 - let caught_e523 = 1 + catch /^Vim\%((\a\+)\)\=:E565/ " catch E565 + let caught_e565 = 1 endtry - call assert_equal(1, caught_e523) + call assert_equal(1, caught_e565) au! InsertCharPre new diff --git a/src/nvim/testdir/test_excmd.vim b/src/nvim/testdir/test_excmd.vim index 7dde8a0439..b3052abb24 100644 --- a/src/nvim/testdir/test_excmd.vim +++ b/src/nvim/testdir/test_excmd.vim @@ -401,6 +401,30 @@ func Test_winsize_cmd() " Actually changing the window size would be flaky. endfunc +" Test for running Ex commands when text is locked. +" e in the command line is used to lock the text +func Test_run_excmd_with_text_locked() + " :quit + let cmd = ":\eexecute('quit')\\" + call assert_fails("call feedkeys(cmd, 'xt')", 'E565:') + + " :qall + let cmd = ":\eexecute('qall')\\" + call assert_fails("call feedkeys(cmd, 'xt')", 'E565:') + + " :exit + let cmd = ":\eexecute('exit')\\" + call assert_fails("call feedkeys(cmd, 'xt')", 'E565:') + + " :close - should be ignored + new + let cmd = ":\eexecute('close')\\" + call assert_equal(2, winnr('$')) + close + + call assert_fails("call feedkeys(\":\=execute('bnext')\\", 'xt')", 'E565:') +endfunc + func Test_not_break_expression_register() call setreg('=', '1+1') if 0 diff --git a/src/nvim/testdir/test_gf.vim b/src/nvim/testdir/test_gf.vim index 589899f532..7cb9daf59a 100644 --- a/src/nvim/testdir/test_gf.vim +++ b/src/nvim/testdir/test_gf.vim @@ -147,5 +147,20 @@ func Test_gf_error() call setline(1, '/doesnotexist') call assert_fails('normal gf', 'E447:') call assert_fails('normal gF', 'E447:') + call assert_fails('normal [f', 'E447:') + + " gf is not allowed when text is locked + au InsertCharPre normal! gF + let caught_e565 = 0 + try + call feedkeys("ix\", 'xt') + catch /^Vim\%((\a\+)\)\=:E565/ " catch E565 + let caught_e565 = 1 + endtry + call assert_equal(1, caught_e565) + au! InsertCharPre + bwipe! endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim index 48358f71b8..7afa31a6d1 100644 --- a/src/nvim/testdir/test_popup.vim +++ b/src/nvim/testdir/test_popup.vim @@ -349,19 +349,17 @@ func DummyCompleteOne(findstart, base) endif endfunc -" Test that nothing happens if the 'completefunc' opens -" a new window (no completion, no crash) +" Test that nothing happens if the 'completefunc' tries to open +" a new window (fails to open window, continues) func Test_completefunc_opens_new_window_one() new let winid = win_getid() setlocal completefunc=DummyCompleteOne call setline(1, 'one') /^one - call assert_fails('call feedkeys("A\\\\", "x")', 'E839:') - call assert_notequal(winid, win_getid()) - q! + call assert_fails('call feedkeys("A\\\\", "x")', 'E565:') call assert_equal(winid, win_getid()) - call assert_equal('', getline(1)) + call assert_equal('oneDEF', getline(1)) q! endfunc -- cgit