aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-04-25 21:40:46 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-04-29 15:51:04 +0800
commit66747f18ded775e2c0b6bac73cee18a3752086af (patch)
treed0a25e517a61819d379115c7237080e284e90beb
parent82a13a78bb26e91d9f81231ab5e725129cfd8757 (diff)
downloadrneovim-66747f18ded775e2c0b6bac73cee18a3752086af.tar.gz
rneovim-66747f18ded775e2c0b6bac73cee18a3752086af.tar.bz2
rneovim-66747f18ded775e2c0b6bac73cee18a3752086af.zip
vim-patch:8.2.0839: dropping modifier when putting a character back in typeahead
Problem: Dropping modifier when putting a character back in typeahead. Solution: Add modifier to ins_char_typebuf(). (closes vim/vim#6158) https://github.com/vim/vim/commit/b42c0d54279b1fdb79652db0c84171e213458809 Vim's test doesn't seem to work properly as the hit-enter prompt seems to be delayed. Add a Lua screen test.
-rw-r--r--src/nvim/getchar.c6
-rw-r--r--src/nvim/globals.h3
-rw-r--r--src/nvim/message.c2
-rw-r--r--src/nvim/normal.c2
-rw-r--r--src/nvim/terminal.c2
-rw-r--r--src/nvim/testdir/test_messages.vim8
-rw-r--r--test/functional/ui/input_spec.lua33
7 files changed, 53 insertions, 3 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index f92aa14c78..fbe503bcd4 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -1499,6 +1499,8 @@ int vgetc(void)
static size_t last_vgetc_recorded_len = 0;
mod_mask = 0;
+ vgetc_mod_mask = 0;
+ vgetc_char = 0;
// last_recorded_len can be larger than last_vgetc_recorded_len
// if peeking records more
@@ -1624,6 +1626,10 @@ int vgetc(void)
// A modifier was not used for a mapping, apply it to ASCII
// keys. Shift would already have been applied.
+ // Remember the character and mod_mask from before, in some
+ // cases they are put back in the typeahead buffer.
+ vgetc_mod_mask = mod_mask;
+ vgetc_char = c;
c = merge_modifiers(c);
// If mappings are enabled (i.e., not Ctrl-v) and the user directly typed
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index e07a0e22ca..6e0b445656 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -129,6 +129,9 @@ typedef off_t off_T;
// held down based on the MOD_MASK_* symbols that are read first.
EXTERN int mod_mask INIT(= 0); // current key modifiers
+// The value of "mod_mask" and the unmodified character before calling merge_modifiers().
+EXTERN int vgetc_mod_mask INIT(= 0);
+EXTERN int vgetc_char INIT(= 0);
// Cmdline_row is the row where the command line starts, just below the
// last window.
diff --git a/src/nvim/message.c b/src/nvim/message.c
index 6708001495..90af920396 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -1214,7 +1214,7 @@ void wait_return(int redraw)
} else if (vim_strchr((char_u *)"\r\n ", c) == NULL && c != Ctrl_C) {
// Put the character back in the typeahead buffer. Don't use the
// stuff buffer, because lmaps wouldn't work.
- ins_char_typebuf(c, mod_mask);
+ ins_char_typebuf(vgetc_char, vgetc_mod_mask);
do_redraw = true; // need a redraw even though there is
// typeahead
}
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 73ea995d8f..a04316f5e4 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -995,7 +995,7 @@ static int normal_execute(VimState *state, int key)
// restart automatically.
// Insert the typed character in the typeahead buffer, so that it can
// be mapped in Insert mode. Required for ":lmap" to work.
- int len = ins_char_typebuf(s->c, mod_mask);
+ int len = ins_char_typebuf(vgetc_char, vgetc_mod_mask);
// When recording and gotchars() was called the character will be
// recorded again, remove the previous recording.
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index fd870361c7..5f536c0b7a 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -1348,7 +1348,7 @@ static bool send_mouse_event(Terminal *term, int c)
}
end:
- ins_char_typebuf(c, mod_mask);
+ ins_char_typebuf(vgetc_char, vgetc_mod_mask);
return true;
}
diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim
index 82c4cc128b..2e9b0a8531 100644
--- a/src/nvim/testdir/test_messages.vim
+++ b/src/nvim/testdir/test_messages.vim
@@ -112,6 +112,14 @@ func Test_echospace()
set ruler& showcmd&
endfunc
+func Test_mapping_at_hit_return_prompt()
+ nnoremap <C-B> :echo "hit ctrl-b"<CR>
+ call feedkeys(":ls\<CR>", "xt")
+ call feedkeys("\<C-B>", "xt")
+ call assert_match('hit ctrl-b', Screenline(&lines - 1))
+ nunmap <C-B>
+endfunc
+
func Test_quit_long_message()
CheckScreendump
diff --git a/test/functional/ui/input_spec.lua b/test/functional/ui/input_spec.lua
index 8925dda730..799aad8d55 100644
--- a/test/functional/ui/input_spec.lua
+++ b/test/functional/ui/input_spec.lua
@@ -216,6 +216,39 @@ it('Ctrl-6 is Ctrl-^ vim-patch:8.1.2333', function()
eq('aaa', funcs.bufname())
end)
+it('typing a simplifiable key at hit-enter prompt triggers mapping vim-patch:8.2.0839', function()
+ local screen = Screen.new(60,8)
+ screen:set_default_attr_ids({
+ [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ [2] = {bold = true, reverse = true}, -- MsgSeparator
+ [3] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg
+ })
+ screen:attach()
+ command([[nnoremap <C-6> <Cmd>echo 'hit ctrl-6'<CR>]])
+ feed_command('ls')
+ screen:expect([[
+ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {2: }|
+ :ls |
+ 1 %a "[No Name]" line 1 |
+ {3:Press ENTER or type command to continue}^ |
+ ]])
+ feed('<C-6>')
+ screen:expect([[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ hit ctrl-6 |
+ ]])
+end)
+
describe('input non-printable chars', function()
after_each(function()
os.remove('Xtest-overwrite')