vim-patch:8.0.1482: using feedkeys() does not work to test completion

Problem:    Using feedkeys() does not work to test Insert mode completion.
            (Lifepillar)
Solution:   Do not check for typed keys when executing :normal or feedkeys().
            Fix thesaurus completion not working when 'complete' is empty.
02ae9b4a93
This commit is contained in:
Jan Edmund Lazo
2019-06-23 22:04:46 -04:00
parent 162bc62f56
commit ed2d651b50
4 changed files with 28 additions and 14 deletions

View File

@@ -514,7 +514,7 @@ static int insert_check(VimState *state)
// If typed something may trigger CursorHoldI again. // If typed something may trigger CursorHoldI again.
if (s->c != K_EVENT if (s->c != K_EVENT
// but not in CTRL-X mode, a script can't restore the state // but not in CTRL-X mode, a script can't restore the state
&& ctrl_x_mode == 0) { && ctrl_x_mode == CTRL_X_NORMAL) {
did_cursorhold = false; did_cursorhold = false;
} }
@@ -523,7 +523,10 @@ static int insert_check(VimState *state)
s->inserted_space = false; s->inserted_space = false;
} }
if (can_cindent && cindent_on() && ctrl_x_mode == 0 && !compl_started) { if (can_cindent
&& cindent_on()
&& ctrl_x_mode == CTRL_X_NORMAL
&& !compl_started) {
insert_do_cindent(s); insert_do_cindent(s);
} }
@@ -1209,7 +1212,8 @@ check_pum:
// if 'complete' is empty then plain ^P is no longer special, // if 'complete' is empty then plain ^P is no longer special,
// but it is under other ^X modes // but it is under other ^X modes
if (*curbuf->b_p_cpt == NUL if (*curbuf->b_p_cpt == NUL
&& ctrl_x_mode != 0 && (ctrl_x_mode == CTRL_X_NORMAL
|| ctrl_x_mode == CTRL_X_WHOLE_LINE)
&& !(compl_cont_status & CONT_LOCAL)) { && !(compl_cont_status & CONT_LOCAL)) {
goto normalchar; goto normalchar;
} }
@@ -4535,12 +4539,12 @@ void ins_compl_check_keys(int frequency, int in_compl_func)
{ {
static int count = 0; static int count = 0;
int c; // Don't check when reading keys from a script, :normal or feedkeys().
// That would break the test scripts. But do check for keys when called
/* Don't check when reading keys from a script. That would break the test // from complete_check().
* scripts */ if (!in_compl_func && (using_script() || ex_normal_busy)) {
if (using_script())
return; return;
}
/* Only do this at regular intervals */ /* Only do this at regular intervals */
if (++count < frequency) if (++count < frequency)
@@ -4549,7 +4553,7 @@ void ins_compl_check_keys(int frequency, int in_compl_func)
/* Check for a typed key. Do use mappings, otherwise vim_is_ctrl_x_key() /* Check for a typed key. Do use mappings, otherwise vim_is_ctrl_x_key()
* can't do its work correctly. */ * can't do its work correctly. */
c = vpeekc_any(); int c = vpeekc_any();
if (c != NUL) { if (c != NUL) {
if (vim_is_ctrl_x_key(c) && c != Ctrl_X && c != Ctrl_R) { if (vim_is_ctrl_x_key(c) && c != Ctrl_X && c != Ctrl_R) {
c = safe_vgetc(); /* Eat the character */ c = safe_vgetc(); /* Eat the character */

View File

@@ -643,11 +643,11 @@ func! Test_edit_CTRL_L()
call feedkeys("cct\<c-x>\<c-l>\<c-n>\<esc>", 'tnix') call feedkeys("cct\<c-x>\<c-l>\<c-n>\<esc>", 'tnix')
call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$'))
call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<esc>", 'tnix') call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<esc>", 'tnix')
call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$'))
call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix')
call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$')) call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$'))
call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix') call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix')
call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$'))
call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix')
call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$'))
call feedkeys("cct\<c-x>\<c-l>\<c-p>\<esc>", 'tnix') call feedkeys("cct\<c-x>\<c-l>\<c-p>\<esc>", 'tnix')
call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$')) call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$'))
call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<esc>", 'tnix') call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<esc>", 'tnix')
@@ -1408,7 +1408,6 @@ func Test_edit_complete_very_long_name()
let save_columns = &columns let save_columns = &columns
" Need at least about 1100 columns to reproduce the problem. " Need at least about 1100 columns to reproduce the problem.
set columns=2000 set columns=2000
call assert_equal(2000, &columns)
set noswapfile set noswapfile
let longfilename = longdirname . '/' . repeat('a', 255) let longfilename = longdirname . '/' . repeat('a', 255)

View File

@@ -249,3 +249,14 @@ func Test_omni_dash()
delfunc Omni delfunc Omni
set omnifunc= set omnifunc=
endfunc endfunc
" Check that when using feedkeys() typeahead does not interrupt searching for
" completions.
func Test_compl_feedkeys()
new
set completeopt=menuone,noselect
call feedkeys("ajump ju\<C-X>\<C-N>\<C-P>\<ESC>", "tx")
call assert_equal("jump jump", getline(1))
bwipe!
set completeopt&
endfunc

View File

@@ -641,7 +641,7 @@ func Test_popup_and_preview_autocommand()
norm! gt norm! gt
call assert_equal(0, &previewwindow) call assert_equal(0, &previewwindow)
norm! gT norm! gT
call assert_equal(12, tabpagenr('$')) call assert_equal(10, tabpagenr('$'))
tabonly tabonly
pclose pclose
augroup MyBufAdd augroup MyBufAdd