diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-07-17 21:42:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-17 21:42:55 +0800 |
commit | d0d132fbd055834cbecb3d4e3a123a6ea8f099ec (patch) | |
tree | f4fc189995f1d29ee5d4137cba1c8e89a2e6e116 | |
parent | 881d17a11393da75a27c072faa3fd45f510175fe (diff) | |
download | rneovim-d0d132fbd055834cbecb3d4e3a123a6ea8f099ec.tar.gz rneovim-d0d132fbd055834cbecb3d4e3a123a6ea8f099ec.tar.bz2 rneovim-d0d132fbd055834cbecb3d4e3a123a6ea8f099ec.zip |
fix(terminal): don't send unknown special keys to terminal (#24378)
Special keys are negative integers, so sending them to terminal leads to
strange behavior.
-rw-r--r-- | src/nvim/terminal.c | 2 | ||||
-rw-r--r-- | test/functional/terminal/buffer_spec.lua | 24 |
2 files changed, 25 insertions, 1 deletions
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 1479656bca..caa4674cef 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -766,7 +766,7 @@ void terminal_send_key(Terminal *term, int c) if (key) { vterm_keyboard_key(term->vt, key, mod); - } else { + } else if (!IS_SPECIAL(c)) { vterm_keyboard_unichar(term->vt, (uint32_t)c, mod); } } diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index bd898ba99e..8b43f5cf9c 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -431,6 +431,30 @@ it('terminal truncates number of composing characters to 5', function() retry(nil, nil, function() eq('a' .. composing:rep(5), meths.get_current_line()) end) end) +describe('terminal input', function() + before_each(function() + clear() + exec_lua([[ + _G.input_data = '' + vim.api.nvim_open_term(0, { on_input = function(_, _, _, data) + _G.input_data = _G.input_data .. data + end }) + ]]) + command('startinsert') + poke_eventloop() + end) + + it('<C-Space> is sent as NUL byte', function() + feed('aaa<C-Space>bbb') + eq('aaa\0bbb', exec_lua([[return _G.input_data]])) + end) + + it('unknown special keys are not sent', function() + feed('aaa<Help>bbb') + eq('aaabbb', exec_lua([[return _G.input_data]])) + end) +end) + if is_os('win') then describe(':terminal in Windows', function() local screen |