aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-06-17 07:28:16 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-07-25 09:47:28 +0800
commiteb77122823f35c2296cc332aec7f4380db6dafe7 (patch)
treeeb7baf2dee159b46833499d0a49eadf8919f7a42
parent46e3e1c7280a409462cceb520fe12259b5ba9937 (diff)
downloadrneovim-eb77122823f35c2296cc332aec7f4380db6dafe7.tar.gz
rneovim-eb77122823f35c2296cc332aec7f4380db6dafe7.tar.bz2
rneovim-eb77122823f35c2296cc332aec7f4380db6dafe7.zip
fix(input): do no reinterpret mouse keys with ALT modifiers
Remove check for MOD_MASK_META as it is for <T- which never appears in TUI. Make small changes to docs.
-rw-r--r--runtime/doc/cmdline.txt2
-rw-r--r--runtime/doc/insert.txt2
-rw-r--r--runtime/doc/intro.txt4
-rw-r--r--runtime/doc/vim_diff.txt2
-rw-r--r--runtime/doc/visual.txt3
-rw-r--r--src/nvim/getchar.c17
-rw-r--r--test/functional/editor/meta_key_spec.lua2
-rw-r--r--test/functional/ui/statusline_spec.lua48
8 files changed, 57 insertions, 23 deletions
diff --git a/runtime/doc/cmdline.txt b/runtime/doc/cmdline.txt
index 3f3f1e6ba3..5d82f5985b 100644
--- a/runtime/doc/cmdline.txt
+++ b/runtime/doc/cmdline.txt
@@ -240,7 +240,7 @@ CTRL-[ *c_CTRL-[* *c_<Esc>* *c_Esc*
Note: If your <Esc> key is hard to hit on your keyboard, train
yourself to use CTRL-[.
*c_META* *c_ALT*
- ALT (|META|) acts like <Esc> if the chord is not mapped.
+ ALT (|META|) may act like <Esc> if the chord is not mapped.
For example <A-x> acts like <Esc>x if <A-x> does not have a
command-line mode mapping.
*c_CTRL-C*
diff --git a/runtime/doc/insert.txt b/runtime/doc/insert.txt
index a16d88b4e9..27f1fed751 100644
--- a/runtime/doc/insert.txt
+++ b/runtime/doc/insert.txt
@@ -39,7 +39,7 @@ char action ~
abbreviation.
Note: If your <Esc> key is hard to hit, try CTRL-[ instead.
*i_META* *i_ALT*
- ALT (|META|) acts like <Esc> if the chord is not mapped.
+ ALT (|META|) may act like <Esc> if the chord is not mapped.
For example <A-x> acts like <Esc>x if <A-x> does not have an
insert-mode mapping.
*i_CTRL-C*
diff --git a/runtime/doc/intro.txt b/runtime/doc/intro.txt
index 51e823b75f..92ba7b4079 100644
--- a/runtime/doc/intro.txt
+++ b/runtime/doc/intro.txt
@@ -383,8 +383,8 @@ Note:
<k1>, ..., <k9> and <kPoint> will not work.
- Nvim supports mapping multibyte chars with modifiers such as `<M-รค>`. Which
combinations actually work depends on the the UI or host terminal.
-- When a key is pressed using a meta or alt modifier and no mapping exists
- for that keypress, Nvim behaves as though <Esc> was pressed before the key.
+- When a key is pressed using a meta or alt modifier and no mapping exists for
+ that keypress, Nvim may behave as though <Esc> was pressed before the key.
- It is possible to notate combined modifiers (e.g. <C-A-T> for CTRL-ALT-T),
but your terminal must encode the input for that to work. |tui-input|
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt
index a74149d050..27c953a460 100644
--- a/runtime/doc/vim_diff.txt
+++ b/runtime/doc/vim_diff.txt
@@ -250,7 +250,7 @@ Input/Mappings:
<M-1>, <M-BS>, <M-Del>, <M-Ins>, <M-/>, <M-\>, <M-Space>, <M-Enter>, etc.
Case-sensitive: <M-a> and <M-A> are two different keycodes.
- ALT behaves like <Esc> if not mapped. |i_ALT| |v_ALT| |c_ALT|
+ ALT may behave like <Esc> if not mapped. |i_ALT| |v_ALT| |c_ALT|
Normal commands:
|gO| shows a filetype-defined "outline" of the current buffer.
diff --git a/runtime/doc/visual.txt b/runtime/doc/visual.txt
index 905ae49887..5383ea4f72 100644
--- a/runtime/doc/visual.txt
+++ b/runtime/doc/visual.txt
@@ -161,9 +161,10 @@ If you want to highlight exactly the same area as the last time, you can use
*v_<Esc>*
<Esc> In Visual mode: Stop Visual mode.
*v_META* *v_ALT*
- ALT (|META|) acts like <Esc> if the chord is not mapped.
+ ALT (|META|) may act like <Esc> if the chord is not mapped.
For example <A-x> acts like <Esc>x if <A-x> does not have a
visual-mode mapping.
+
*v_CTRL-C*
CTRL-C In Visual mode: Stop Visual mode. When insert mode is
pending (the mode message shows
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index 3e8591b2be..4a5841ca6e 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -30,6 +30,7 @@
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
+#include "nvim/mouse.h"
#include "nvim/move.h"
#include "nvim/normal.h"
#include "nvim/ops.h"
@@ -1584,16 +1585,18 @@ int vgetc(void)
vgetc_char = c;
}
- // If mappings are enabled (i.e., not Ctrl-v) and the user directly typed
- // something with a meta- or alt- modifier that was not mapped, interpret
- // <M-x> as <Esc>x rather than as an unbound meta keypress. #8213
- // In Terminal mode, however, this is not desirable. #16220
- if (!no_mapping && KeyTyped && !(State & MODE_TERMINAL)
- && (mod_mask == MOD_MASK_ALT || mod_mask == MOD_MASK_META)) {
+ // If mappings are enabled (i.e., not i_CTRL-V) and the user directly typed something with
+ // MOD_MASK_ALT (<M-/<A- modifier) that was not mapped, interpret <M-x> as <Esc>x rather
+ // than as an unbound <M-x> keypress. #8213
+ // In Terminal mode, however, this is not desirable. #16202 #16220
+ // Also do not do this for mouse keys, as terminals encode mouse events as CSI sequences, and
+ // MOD_MASK_ALT has a meaning even for unmapped mouse keys.
+ if (!no_mapping && KeyTyped && mod_mask == MOD_MASK_ALT && !(State & MODE_TERMINAL)
+ && !is_mouse_key(c)) {
mod_mask = 0;
int len = ins_char_typebuf(c, 0);
(void)ins_char_typebuf(ESC, 0);
- ungetchars(len + 3); // The ALT/META modifier takes three more bytes
+ ungetchars(len + 3); // K_SPECIAL KS_MODIFIER MOD_MASK_ALT takes 3 more bytes
continue;
}
diff --git a/test/functional/editor/meta_key_spec.lua b/test/functional/editor/meta_key_spec.lua
index 23964ca10f..825b20138a 100644
--- a/test/functional/editor/meta_key_spec.lua
+++ b/test/functional/editor/meta_key_spec.lua
@@ -91,7 +91,7 @@ describe('meta-keys #8226 #13042', function()
command('tnoremap <A-j> alt-j')
feed('i<M-l> xxx <A-j>')
eq('meta-l xxx alt-j', exec_lua([[return _G.input_data]]))
- -- Unmapped ALT-chord is sent to terminal as-is. #16220
+ -- Unmapped ALT-chord is sent to terminal as-is. #16202 #16220
exec_lua([[_G.input_data = '']])
command('tunmap <M-l>')
feed('<M-l>')
diff --git a/test/functional/ui/statusline_spec.lua b/test/functional/ui/statusline_spec.lua
index 760760150c..69a2d2f4ed 100644
--- a/test/functional/ui/statusline_spec.lua
+++ b/test/functional/ui/statusline_spec.lua
@@ -21,11 +21,9 @@ describe('statusline clicks', function()
command('set laststatus=2 mousemodel=extend')
exec([=[
function! MyClickFunc(minwid, clicks, button, mods)
- let mods = trim(a:mods)
- if mods ==# ''
- let g:testvar = printf("%d %d %s", a:minwid, a:clicks, a:button)
- else
- let g:testvar = printf("%d %d %s %s", a:minwid, a:clicks, a:button, mods)
+ let g:testvar = printf("%d %d %s", a:minwid, a:clicks, a:button)
+ if a:mods !=# ' '
+ let g:testvar ..= '(' .. a:mods .. ')'
endif
endfunction
]=])
@@ -35,8 +33,20 @@ describe('statusline clicks', function()
meths.set_option('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T')
meths.input_mouse('left', 'press', '', 0, 6, 17)
eq('0 1 l', eval("g:testvar"))
+ meths.input_mouse('left', 'press', '', 0, 6, 17)
+ eq('0 2 l', eval("g:testvar"))
+ meths.input_mouse('left', 'press', '', 0, 6, 17)
+ eq('0 3 l', eval("g:testvar"))
+ meths.input_mouse('left', 'press', '', 0, 6, 17)
+ eq('0 4 l', eval("g:testvar"))
meths.input_mouse('right', 'press', '', 0, 6, 17)
eq('0 1 r', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 6, 17)
+ eq('0 2 r', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 6, 17)
+ eq('0 3 r', eval("g:testvar"))
+ meths.input_mouse('right', 'press', '', 0, 6, 17)
+ eq('0 4 r', eval("g:testvar"))
end)
it('works for winbar', function()
@@ -101,10 +111,30 @@ describe('statusline clicks', function()
it("works with modifiers #18994", function()
meths.set_option('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T')
- meths.input_mouse('right', 'press', 's', 0, 6, 17)
- eq('0 1 r s', eval("g:testvar"))
- meths.input_mouse('left', 'press', 's', 0, 6, 17)
- eq('0 1 l s', eval("g:testvar"))
+ -- Note: alternate between left and right mouse buttons to avoid triggering multiclicks
+ meths.input_mouse('left', 'press', 'S', 0, 6, 17)
+ eq('0 1 l(s )', eval("g:testvar"))
+ meths.input_mouse('right', 'press', 'S', 0, 6, 17)
+ eq('0 1 r(s )', eval("g:testvar"))
+ meths.input_mouse('left', 'press', 'A', 0, 6, 17)
+ eq('0 1 l( a )', eval("g:testvar"))
+ meths.input_mouse('right', 'press', 'A', 0, 6, 17)
+ eq('0 1 r( a )', eval("g:testvar"))
+ meths.input_mouse('left', 'press', 'AS', 0, 6, 17)
+ eq('0 1 l(s a )', eval("g:testvar"))
+ meths.input_mouse('right', 'press', 'AS', 0, 6, 17)
+ eq('0 1 r(s a )', eval("g:testvar"))
+ meths.input_mouse('left', 'press', 'T', 0, 6, 17)
+ eq('0 1 l( m)', eval("g:testvar"))
+ meths.input_mouse('right', 'press', 'T', 0, 6, 17)
+ eq('0 1 r( m)', eval("g:testvar"))
+ meths.input_mouse('left', 'press', 'TS', 0, 6, 17)
+ eq('0 1 l(s m)', eval("g:testvar"))
+ meths.input_mouse('right', 'press', 'TS', 0, 6, 17)
+ eq('0 1 r(s m)', eval("g:testvar"))
+ meths.input_mouse('left', 'press', 'C', 0, 6, 17)
+ eq('0 1 l( c )', eval("g:testvar"))
+ -- <C-RightMouse> is for tag jump
end)
it("works for global statusline with vertical splits #19186", function()