From 317d5ca7b0f92ef42de989b3556ca9503f0a3bf6 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 10 Jan 2016 16:23:24 -0500 Subject: input: Do not set high-bit; preserve ALT modifier. Background: Vim internally prefers to represent ALT/META chords as single-byte keys, by setting the high bit of the key byte. extract_modifiers() _discards_ the meta/alt modifier, but we need it for libvterm and libtermkey. Closes #2440 Closes #3727 Closes #2017 References #2277 References #2254 https://github.com/neovim/neovim/issues/2017#issuecomment-140423557 > We [not libtermkey] are setting the high bit for some reason https://github.com/neovim/neovim/issues/176#issuecomment-77834715 > libvtermkey requires the leading esc to parse alt/meta https://github.com/neovim/neovim/pull/3246#issuecomment-136328450 > A program could do better than the current logic on some terminals, by > asking for pure 8bit mode (S8C1T) and then immediately querying the > mode again. If the result comes back as an 8bit single-byte CSI, then > it can presume the mode setting was successful, and now the ESC prefix > byte won't be seen in multibyte sequences; only as an Alt- prefix or > a real Escape key. On such a terminal, it could therefore avoid > needing to use that waiting timeout. --- test/functional/terminal/tui_spec.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 14700a2622..838d05a6df 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -53,7 +53,7 @@ describe('tui', function() ]]) end) - it('interprets leading esc byte as the alt modifier', function() + it('interprets leading byte as ALT modifier in normal-mode', function() local keys = 'dfghjkl' for c in keys:gmatch('.') do execute('nnoremap ialt-'..c..'') @@ -80,6 +80,25 @@ describe('tui', function() ]]) end) + it('does not mangle unmapped ALT-key chord', function() + -- Vim represents ALT/META by setting the "high bit" of the modified key; + -- we do _not_. #3982 + -- + -- Example: for input ALT+j: + -- * Vim (Nvim prior to #3982) sets high-bit, inserts "ê". + -- * Nvim (after #3982) inserts "j". + feed('i\x1bj') + screen:expect([[ + j{1: } | + ~ | + ~ | + ~ | + [No Name] [+] | + -- INSERT -- | + -- TERMINAL -- | + ]]) + end) + it('accepts ascii control sequences', function() feed('i') feed('\x16\x07') -- ctrl+g -- cgit