summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShougo Matsushita <Shougo.Matsu@gmail.com>2024-07-17 20:25:22 +0200
committerChristian Brabandt <cb@256bit.org>2024-07-17 20:25:22 +0200
commitfcc1b5741e391c163c9ce979653987c83287ce20 (patch)
treea349fc3c40d7290bb21a40bf7cba6f7af1f05183
parent76c19028ffc8b00816df7bc48985c92f7bacbcfb (diff)
patch 9.1.0597: KeyInputPre cannot get the (unmapped typed) keyv9.1.0597
Problem: KeyInputPre cannot get the (unmapped typed) key (after v9.1.0563) Solution: Add the "typedchar" property to the v:event dict (Shougo Matsushita) closes: #15231 Co-authored-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Shougo Matsushita <Shougo.Matsu@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
-rw-r--r--runtime/doc/autocmd.txt12
-rw-r--r--src/getchar.c19
-rw-r--r--src/testdir/test_autocmd.vim9
-rw-r--r--src/version.c2
4 files changed, 37 insertions, 5 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
index 1e9c896545..0461c0454e 100644
--- a/runtime/doc/autocmd.txt
+++ b/runtime/doc/autocmd.txt
@@ -1,4 +1,4 @@
-*autocmd.txt* For Vim version 9.1. Last change: 2024 Jul 11
+*autocmd.txt* For Vim version 9.1. Last change: 2024 Jul 17
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -980,10 +980,11 @@ InsertLeavePre Just before leaving Insert mode. Also when
InsertLeave Just after leaving Insert mode. Also when
using CTRL-O |i_CTRL-O|. But not for |i_CTRL-C|.
*KeyInputPre*
-KeyInputPre Just before a key is processed. The pattern is
- matched against a string that indicates the
- current mode, which is the same as what is
- returned by `mode(1)`.
+KeyInputPre Just before a key is processed after mappings
+ have been applied. The pattern is matched
+ against a string that indicates the current
+ mode, which is the same as what is returned by
+ `mode(1)`.
The |v:char| variable indicates the key typed
and can be changed during the event to process
a different key. When |v:char| is not a
@@ -991,6 +992,7 @@ KeyInputPre Just before a key is processed. The pattern is
character is used.
The following values of |v:event| are set:
typed The key is typed or not.
+ typedchar The (actual) typed key.
It is not allowed to change the text
|textlock| or the current mode.
{only with the +eval feature}
diff --git a/src/getchar.c b/src/getchar.c
index a0787f5fff..df89f4cd2f 100644
--- a/src/getchar.c
+++ b/src/getchar.c
@@ -42,6 +42,11 @@ static buffheader_T recordbuff = {{NULL, {NUL}}, NULL, 0, 0};
static int typeahead_char = 0; // typeahead char that's not flushed
+#ifdef FEAT_EVAL
+static char_u typedchars[MAXMAPLEN + 1] = { NUL }; // typed chars before map
+static int typedchars_pos = 0;
+#endif
+
/*
* When block_redo is TRUE the redo buffer will not be changed.
* Used by edit() to repeat insertions.
@@ -1709,6 +1714,13 @@ updatescript(int c)
ml_sync_all(c == 0, TRUE);
count = 0;
}
+#ifdef FEAT_EVAL
+ if (typedchars_pos < MAXMAPLEN)
+ {
+ typedchars[typedchars_pos] = c;
+ typedchars_pos++;
+ }
+#endif
}
/*
@@ -2135,6 +2147,9 @@ vgetc(void)
#ifdef FEAT_EVAL
c = do_key_input_pre(c);
+
+ // Clear the next typedchars_pos
+ typedchars_pos = 0;
#endif
// Need to process the character before we know it's safe to do something
@@ -2175,6 +2190,9 @@ do_key_input_pre(int c)
else
buf[(*mb_char2bytes)(c, buf)] = NUL;
+ typedchars[typedchars_pos] = NUL;
+ vim_unescape_csi(typedchars);
+
get_mode(curr_mode);
// Lock the text to avoid weird things from happening.
@@ -2183,6 +2201,7 @@ do_key_input_pre(int c)
v_event = get_v_event(&save_v_event);
(void)dict_add_bool(v_event, "typed", KeyTyped);
+ (void)dict_add_string(v_event, "typedchar", typedchars);
if (apply_autocmds(EVENT_KEYINPUTPRE, curr_mode, curr_mode, FALSE, curbuf)
&& STRCMP(buf, get_vim_var_str(VV_CHAR)) != 0)
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index 5ad1730c40..26590ab33b 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -4820,6 +4820,15 @@ func Test_KeyInputPre()
call feedkeys('j', 'nx')
au! KeyInputPre
+
+ " Test for v:event.typedchar
+ nnoremap j k
+ au KeyInputPre n
+ \ call assert_equal(v:event.typedchar, 'j')
+ \ | call assert_equal(v:char, 'k')
+ call feedkeys('j', 'tx')
+
+ au! KeyInputPre
endfunc
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index e989d6e7c0..e22fe614fb 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 597,
+/**/
596,
/**/
595,