]> granicus.if.org Git - vim/commitdiff
patch 8.2.2426: allowing 'completefunc' to switch windows causes trouble v8.2.2426
authorBram Moolenaar <Bram@vim.org>
Fri, 29 Jan 2021 20:07:07 +0000 (21:07 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 29 Jan 2021 20:07:07 +0000 (21:07 +0100)
Problem:    Allowing 'completefunc' to switch windows causes trouble.
Solution:   use "textwinlock" instead of "textlock".

src/insexpand.c
src/testdir/test_ins_complete.vim
src/testdir/test_popup.vim
src/version.c

index 02f593d7c866e6a5f9146e379172fff6e7139c6b..66507f04363b56ca1b97e82a2f17ac9dd4abaf57 100644 (file)
@@ -2218,9 +2218,10 @@ expand_by_function(
     pos = curwin->w_cursor;
     curwin_save = curwin;
     curbuf_save = curbuf;
-    // Lock the text to avoid weird things from happening.  Do allow switching
-    // to another window temporarily.
-    ++textlock;
+    // Lock the text to avoid weird things from happening.  Also disallow
+    // switching to another window, it should not be needed and may end up in
+    // Insert mode in another buffer.
+    ++textwinlock;
 
     // Call a function, which returns a list or dict.
     if (call_vim_function(funcname, 2, args, &rettv) == OK)
@@ -2243,7 +2244,7 @@ expand_by_function(
                break;
        }
     }
-    --textlock;
+    --textwinlock;
 
     if (curwin_save != curwin || curbuf_save != curbuf)
     {
@@ -3226,7 +3227,7 @@ ins_compl_next(
        return -1;
 
     if (compl_leader != NULL
-                       && (compl_shown_match->cp_flags & CP_ORIGINAL_TEXT) == 0)
+                     && (compl_shown_match->cp_flags & CP_ORIGINAL_TEXT) == 0)
     {
        // Set "compl_shown_match" to the actually shown match, it may differ
        // when "compl_leader" is used to omit some of the matches.
index 5aa26645bf34d34ed55f058bfd8cc47259b181cf..489c1d9d943693a4225c4a0ddc5515228e244c42 100644 (file)
@@ -562,31 +562,24 @@ func Test_completefunc_error()
   call setline(1, ['', 'abcd', ''])
   call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E578:')
 
-  set completefunc&
-  delfunc CompleteFunc
-  delfunc CompleteFunc2
-  close!
-endfunc
-
-func Test_completefunc_error_not_asan()
-  " The following test causes an ASAN failure.
-  CheckNotAsan
-
   " Jump to a different window from the complete function
-  func! CompleteFunc(findstart, base)
+  func CompleteFunc3(findstart, base)
     if a:findstart == 1
       return col('.') - 1
     endif
     wincmd p
     return ['a', 'b']
   endfunc
-  set completefunc=CompleteFunc
+  set completefunc=CompleteFunc3
   new
-  call assert_fails('exe "normal a\<C-X>\<C-U>"', 'E839:')
+  call assert_fails('exe "normal a\<C-X>\<C-U>"', 'E565:')
   close!
 
   set completefunc&
   delfunc CompleteFunc
+  delfunc CompleteFunc2
+  delfunc CompleteFunc3
+  close!
 endfunc
 
 " Test for returning non-string values from 'completefunc'
index 9175ff1f26d6c6f33d7fea70e2406bfc601c0555..2d0625bc0931e12d83a6e90a3b66f32a7ae29d30 100644 (file)
@@ -342,7 +342,7 @@ func Test_completefunc_opens_new_window_one()
   setlocal completefunc=DummyCompleteOne
   call setline(1, 'one')
   /^one
-  call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 'E578:')
+  call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 'E565:')
   call assert_equal(winid, win_getid())
   call assert_equal('onedef', getline(1))
   q!
@@ -642,8 +642,8 @@ func Test_complete_func_mess()
   set completefunc=MessComplete
   new
   call setline(1, 'Ju')
-  call feedkeys("A\<c-x>\<c-u>/\<esc>", 'tx')
-  call assert_equal('Oct/Oct', getline(1))
+  call assert_fails('call feedkeys("A\<c-x>\<c-u>/\<esc>", "tx")', 'E578:')
+  call assert_equal('Jan/', getline(1))
   bwipe!
   set completefunc=
 endfunc
index 2e0da2b3a783de888e3e1e5a1cfde7174e7d6d32..ed17716a7ed6d7527e7d56b03443faba9e08270f 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2426,
 /**/
     2425,
 /**/