mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 00:08:19 +00:00
vim-patch:8.2.2426: allowing 'completefunc' to switch windows causes trouble
Problem: Allowing 'completefunc' to switch windows causes trouble. Solution: use "textwinlock" instead of "textlock".28976e2acc
Assert E565 instead of E578. vim-patch:8.2.0670: cannot change window when evaluating 'completefunc' Problem: Cannot change window when evaluating 'completefunc'. Solution: Make a difference between not changing text or buffers and also not changing window.6adb9ea0a6
vim-patch:8.2.5029: "textlock" is always zero Problem: "textlock" is always zero. Solution: Remove "textlock" and rename "textwinlock" to "textlock". (closes vim/vim#10489)cfe456543e
This commit is contained in:
@@ -3961,7 +3961,9 @@ static void expand_by_function(int type, char_u *base)
|
||||
pos = curwin->w_cursor;
|
||||
curwin_save = curwin;
|
||||
curbuf_save = curbuf;
|
||||
// Lock the text to avoid weird things from happening.
|
||||
// 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.
|
||||
textlock++;
|
||||
|
||||
// Call a function, which returns a list or dict.
|
||||
|
@@ -1062,11 +1062,6 @@ static void f_complete(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
return;
|
||||
}
|
||||
|
||||
const int save_textlock = textlock;
|
||||
// "textlock" is set when evaluating 'completefunc' but we can change text
|
||||
// here.
|
||||
textlock = 0;
|
||||
|
||||
// Check for undo allowed here, because if something was already inserted
|
||||
// the line was already saved for undo and this check isn't done.
|
||||
if (!undo_allowed(curbuf)) {
|
||||
@@ -1081,7 +1076,6 @@ static void f_complete(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
set_completion(startcol - 1, argvars[1].vval.v_list);
|
||||
}
|
||||
}
|
||||
textlock = save_textlock;
|
||||
}
|
||||
|
||||
/// "complete_add()" function
|
||||
|
@@ -2696,14 +2696,12 @@ char_u *get_cmdprompt(void)
|
||||
return ccline.cmdprompt;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return TRUE when the text must not be changed and we can't switch to
|
||||
* another window or buffer. Used when editing the command line etc.
|
||||
*/
|
||||
int text_locked(void)
|
||||
/// Return true when the text must not be changed and we can't switch to
|
||||
/// another window or buffer. True when editing the command line etc.
|
||||
bool text_locked(void)
|
||||
{
|
||||
if (cmdwin_type != 0) {
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
return textlock != 0;
|
||||
}
|
||||
|
@@ -628,31 +628,24 @@ func Test_completefunc_error()
|
||||
call setline(1, ['', 'abcd', ''])
|
||||
call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E565:')
|
||||
|
||||
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'
|
||||
|
@@ -655,8 +655,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")', 'E565:')
|
||||
call assert_equal('Jan/', getline(1))
|
||||
bwipe!
|
||||
set completefunc=
|
||||
endfunc
|
||||
|
@@ -3143,7 +3143,7 @@ endfunc
|
||||
func Test_vimgrep_with_textlock()
|
||||
new
|
||||
|
||||
" Simple way to execute something with "textwinlock" set.
|
||||
" Simple way to execute something with "textlock" set.
|
||||
" Check that vimgrep without jumping can be executed.
|
||||
au InsertCharPre * vimgrep /RunTheTest/j runtest.vim
|
||||
normal ax
|
||||
|
Reference in New Issue
Block a user