vim-patch:7.4.1758, 7.4.1759, 7.4.1692 #5640

vim-patch:7.4.1758

Problem:    Triggering CursorHoldI when in CTRL-X mode causes problems.
Solution:   Do not trigger CursorHoldI in CTRL-X mode. Add "!" flag to
            feedkeys() (test with that didn't work though).

245c41070c

vim-patch:7.4.1759

Problem:    When using feedkeys() in a timer the inserted characters are not
            used right away.
Solution:   Break the wait loop when characters have been added to typebuf.
            use this for testing CursorHoldI.

40b1b5443c

vim-patch:7.4.1692
Problem:    feedkeys('i', 'x') gets stuck, waits for a character to be typed.
Solution:   Behave like ":normal". (Yasuhiro Matsumoto)
This commit is contained in:
Shougo Matsushita
2016-11-22 06:52:51 +09:00
committed by Justin M. Keyes
parent 880ce887ed
commit 7da7ff7c5c
5 changed files with 45 additions and 4 deletions

View File

@@ -61,6 +61,7 @@ void nvim_feedkeys(String keys, String mode, Boolean escape_csi)
bool insert = false;
bool typed = false;
bool execute = false;
bool dangerous = false;
for (size_t i = 0; i < mode.size; ++i) {
switch (mode.data[i]) {
@@ -69,6 +70,7 @@ void nvim_feedkeys(String keys, String mode, Boolean escape_csi)
case 't': typed = true; break;
case 'i': insert = true; break;
case 'x': execute = true; break;
case '!': dangerous = true; break;
}
}
@@ -99,7 +101,13 @@ void nvim_feedkeys(String keys, String mode, Boolean escape_csi)
/* Avoid a 1 second delay when the keys start Insert mode. */
msg_scroll = false;
if (!dangerous) {
ex_normal_busy++;
}
exec_normal(true);
if (!dangerous) {
ex_normal_busy--;
}
msg_scroll |= save_msg_scroll;
}
}

View File

@@ -474,7 +474,9 @@ static int insert_check(VimState *state)
InsertState *s = (InsertState *)state;
// 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
&& ctrl_x_mode == 0) {
did_cursorhold = false;
}

View File

@@ -6,3 +6,30 @@ func Test_vim_did_enter()
" This script will never reach the main loop, can't check if v:vim_did_enter
" becomes one.
endfunc
if !has('timers')
finish
endif
func ExitInsertMode(id)
call feedkeys("\<Esc>")
endfunc
func Test_cursorhold_insert()
let g:triggered = 0
au CursorHoldI * let g:triggered += 1
set updatetime=20
call timer_start(100, 'ExitInsertMode')
call feedkeys('a', 'x!')
call assert_equal(1, g:triggered)
endfunc
func Test_cursorhold_insert_ctrl_x()
let g:triggered = 0
au CursorHoldI * let g:triggered += 1
set updatetime=20
call timer_start(100, 'ExitInsertMode')
" CursorHoldI does not trigger after CTRL-X
call feedkeys("a\<C-X>", 'x!')
call assert_equal(0, g:triggered)
endfunc

View File

@@ -6,5 +6,9 @@ func Test_feedkeys_x_with_empty_string()
call assert_equal('', getline('.'))
call feedkeys('', 'x')
call assert_equal('foo', getline('.'))
" check it goes back to normal mode immediately.
call feedkeys('i', 'x')
call assert_equal('foo', getline('.'))
quit!
endfunc

View File

@@ -684,8 +684,8 @@ static int included_patches[] = {
// 1762,
// 1761,
// 1760 NA
// 1759,
// 1758,
1759,
1758,
1757,
// 1756 NA
1755,
@@ -752,7 +752,7 @@ static int included_patches[] = {
1695,
// 1694 NA
// 1693 NA
// 1692,
1692,
1691,
// 1690 NA
// 1689 NA