summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_autocmd.vim
diff options
context:
space:
mode:
Diffstat (limited to 'src/testdir/test_autocmd.vim')
-rw-r--r--src/testdir/test_autocmd.vim70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index bcbddf9789..5ad1730c40 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -4752,4 +4752,74 @@ func Test_BufEnter_botline()
set hidden&vim
endfunc
+func Test_KeyInputPre()
+ " Consume previous keys
+ call feedkeys('', 'ntx')
+
+ " KeyInputPre can record input keys.
+ let s:keys = []
+ au KeyInputPre n call add(s:keys, v:char)
+
+ call feedkeys('jkjkjjj', 'ntx')
+ call assert_equal(
+ \ ['j', 'k', 'j', 'k', 'j', 'j', 'j'],
+ \ s:keys)
+
+ unlet s:keys
+ au! KeyInputPre
+
+ " KeyInputPre can handle multibyte.
+ let s:keys = []
+ au KeyInputPre * call add(s:keys, v:char)
+ edit Xxx1
+
+ call feedkeys("iあ\<ESC>", 'ntx')
+ call assert_equal(['i', "あ", "\<ESC>"], s:keys)
+
+ bwipe! Xxx1
+ unlet s:keys
+ au! KeyInputPre
+
+ " KeyInputPre can change input keys.
+ au KeyInputPre i if v:char ==# 'a' | let v:char = 'b' | endif
+ edit Xxx1
+
+ call feedkeys("iaabb\<ESC>", 'ntx')
+ call assert_equal(getline('.'), 'bbbb')
+
+ bwipe! Xxx1
+ au! KeyInputPre
+
+ " KeyInputPre returns multiple characters.
+ au KeyInputPre i if v:char ==# 'a' | let v:char = 'cccc' | endif
+ edit Xxx1
+
+ call feedkeys("iaabb\<ESC>", 'ntx')
+ call assert_equal(getline('.'), 'ccbb')
+
+ bwipe! Xxx1
+ au! KeyInputPre
+
+ " KeyInputPre can use special keys.
+ au KeyInputPre i if v:char ==# 'a' | let v:char = "\<Ignore>" | endif
+ edit Xxx1
+
+ call feedkeys("iaabb\<ESC>", 'ntx')
+ call assert_equal(getline('.'), 'bb')
+
+ bwipe! Xxx1
+ au! KeyInputPre
+
+ " Test for v:event.typed
+ au KeyInputPre n call assert_true(v:event.typed)
+ call feedkeys('j', 'ntx')
+
+ au! KeyInputPre
+
+ au KeyInputPre n call assert_false(v:event.typed)
+ call feedkeys('j', 'nx')
+
+ au! KeyInputPre
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab