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.
This commit is contained in:
zeertzjq 2022-06-17 07:28:16 +08:00
parent 46e3e1c728
commit eb77122823
8 changed files with 57 additions and 23 deletions

View File

@ -240,7 +240,7 @@ CTRL-[ *c_CTRL-[* *c_<Esc>* *c_Esc*
Note: If your <Esc> key is hard to hit on your keyboard, train Note: If your <Esc> key is hard to hit on your keyboard, train
yourself to use CTRL-[. yourself to use CTRL-[.
*c_META* *c_ALT* *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 For example <A-x> acts like <Esc>x if <A-x> does not have a
command-line mode mapping. command-line mode mapping.
*c_CTRL-C* *c_CTRL-C*

View File

@ -39,7 +39,7 @@ char action ~
abbreviation. abbreviation.
Note: If your <Esc> key is hard to hit, try CTRL-[ instead. Note: If your <Esc> key is hard to hit, try CTRL-[ instead.
*i_META* *i_ALT* *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 For example <A-x> acts like <Esc>x if <A-x> does not have an
insert-mode mapping. insert-mode mapping.
*i_CTRL-C* *i_CTRL-C*

View File

@ -383,8 +383,8 @@ Note:
<k1>, ..., <k9> and <kPoint> will not work. <k1>, ..., <k9> and <kPoint> will not work.
- Nvim supports mapping multibyte chars with modifiers such as `<M-ä>`. Which - Nvim supports mapping multibyte chars with modifiers such as `<M-ä>`. Which
combinations actually work depends on the the UI or host terminal. 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 - When a key is pressed using a meta or alt modifier and no mapping exists for
for that keypress, Nvim behaves as though <Esc> was pressed before the key. 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), - 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| but your terminal must encode the input for that to work. |tui-input|

View File

@ -250,7 +250,7 @@ Input/Mappings:
<M-1>, <M-BS>, <M-Del>, <M-Ins>, <M-/>, <M-\>, <M-Space>, <M-Enter>, etc. <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. 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: Normal commands:
|gO| shows a filetype-defined "outline" of the current buffer. |gO| shows a filetype-defined "outline" of the current buffer.

View File

@ -161,9 +161,10 @@ If you want to highlight exactly the same area as the last time, you can use
*v_<Esc>* *v_<Esc>*
<Esc> In Visual mode: Stop Visual mode. <Esc> In Visual mode: Stop Visual mode.
*v_META* *v_ALT* *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 For example <A-x> acts like <Esc>x if <A-x> does not have a
visual-mode mapping. visual-mode mapping.
*v_CTRL-C* *v_CTRL-C*
CTRL-C In Visual mode: Stop Visual mode. When insert mode is CTRL-C In Visual mode: Stop Visual mode. When insert mode is
pending (the mode message shows pending (the mode message shows

View File

@ -30,6 +30,7 @@
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/message.h" #include "nvim/message.h"
#include "nvim/mouse.h"
#include "nvim/move.h" #include "nvim/move.h"
#include "nvim/normal.h" #include "nvim/normal.h"
#include "nvim/ops.h" #include "nvim/ops.h"
@ -1584,16 +1585,18 @@ int vgetc(void)
vgetc_char = c; vgetc_char = c;
} }
// If mappings are enabled (i.e., not Ctrl-v) and the user directly typed // If mappings are enabled (i.e., not i_CTRL-V) and the user directly typed something with
// something with a meta- or alt- modifier that was not mapped, interpret // MOD_MASK_ALT (<M-/<A- modifier) that was not mapped, interpret <M-x> as <Esc>x rather
// <M-x> as <Esc>x rather than as an unbound meta keypress. #8213 // than as an unbound <M-x> keypress. #8213
// In Terminal mode, however, this is not desirable. #16220 // In Terminal mode, however, this is not desirable. #16202 #16220
if (!no_mapping && KeyTyped && !(State & MODE_TERMINAL) // Also do not do this for mouse keys, as terminals encode mouse events as CSI sequences, and
&& (mod_mask == MOD_MASK_ALT || mod_mask == MOD_MASK_META)) { // 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; mod_mask = 0;
int len = ins_char_typebuf(c, 0); int len = ins_char_typebuf(c, 0);
(void)ins_char_typebuf(ESC, 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; continue;
} }

View File

@ -91,7 +91,7 @@ describe('meta-keys #8226 #13042', function()
command('tnoremap <A-j> alt-j') command('tnoremap <A-j> alt-j')
feed('i<M-l> xxx <A-j>') feed('i<M-l> xxx <A-j>')
eq('meta-l xxx alt-j', exec_lua([[return _G.input_data]])) 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 = '']]) exec_lua([[_G.input_data = '']])
command('tunmap <M-l>') command('tunmap <M-l>')
feed('<M-l>') feed('<M-l>')

View File

@ -21,11 +21,9 @@ describe('statusline clicks', function()
command('set laststatus=2 mousemodel=extend') command('set laststatus=2 mousemodel=extend')
exec([=[ exec([=[
function! MyClickFunc(minwid, clicks, button, mods) 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) let g:testvar = printf("%d %d %s", a:minwid, a:clicks, a:button)
else if a:mods !=# ' '
let g:testvar = printf("%d %d %s %s", a:minwid, a:clicks, a:button, mods) let g:testvar ..= '(' .. a:mods .. ')'
endif endif
endfunction endfunction
]=]) ]=])
@ -35,8 +33,20 @@ describe('statusline clicks', function()
meths.set_option('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T') meths.set_option('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T')
meths.input_mouse('left', 'press', '', 0, 6, 17) meths.input_mouse('left', 'press', '', 0, 6, 17)
eq('0 1 l', eval("g:testvar")) 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) meths.input_mouse('right', 'press', '', 0, 6, 17)
eq('0 1 r', eval("g:testvar")) 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) end)
it('works for winbar', function() it('works for winbar', function()
@ -101,10 +111,30 @@ describe('statusline clicks', function()
it("works with modifiers #18994", function() it("works with modifiers #18994", function()
meths.set_option('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T') meths.set_option('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T')
meths.input_mouse('right', 'press', 's', 0, 6, 17) -- Note: alternate between left and right mouse buttons to avoid triggering multiclicks
eq('0 1 r s', eval("g:testvar")) meths.input_mouse('left', 'press', 'S', 0, 6, 17)
meths.input_mouse('left', 'press', 's', 0, 6, 17) eq('0 1 l(s )', eval("g:testvar"))
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) end)
it("works for global statusline with vertical splits #19186", function() it("works for global statusline with vertical splits #19186", function()