From 562719033ec8bec9f6d56c166b9aef13f8a50a96 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 18 Apr 2024 06:23:11 +0800 Subject: vim-patch:9.1.0343: 'showcmd' wrong for partial mapping with multibyte (#28392) Problem: 'showcmd' is wrong for partial mapping with multibyte char, and isn't very readable with modifyOtherKeys. Solution: Decode multibyte char and merge modifiers into the char. (zeertzjq) This improves the following situations: - Multibyte chars whose individual bytes are considered unprintable are now shown properly in 'showcmd' area. - Ctrl-W with modifyOtherKeys now shows ^W in 'showcmd' area. The following situation may still need improvement: - If the char is a special key or has modifiers that cannot be merged into it, internal keycodes are shown in 'showcmd' area like before. This applies to keys typed in Normal mode commands as well, and it's hard to decide how to make it more readable due to the limited space taken by 'showcmd', so I'll leave it for later. closes: vim/vim#14572 https://github.com/vim/vim/commit/acdfb8a97995e0f81832207e39564ba795281108 --- test/functional/legacy/mapping_spec.lua | 76 +++++++++++++++++++++++++++++++-- test/old/testdir/test_mapping.vim | 45 ++++++++++++++++++- 2 files changed, 116 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/functional/legacy/mapping_spec.lua b/test/functional/legacy/mapping_spec.lua index 272a79fa29..1078daec64 100644 --- a/test/functional/legacy/mapping_spec.lua +++ b/test/functional/legacy/mapping_spec.lua @@ -1,9 +1,11 @@ -- Test for mappings and abbreviations local t = require('test.functional.testutil')() +local Screen = require('test.functional.ui.screen') local clear, feed, insert = t.clear, t.feed, t.insert local expect, poke_eventloop = t.expect, t.poke_eventloop local command, eq, eval, api = t.command, t.eq, t.eval, t.api +local exec = t.exec local sleep = vim.uv.sleep describe('mapping', function() @@ -23,6 +25,7 @@ describe('mapping', function() vim ]]) end) + -- oldtest: Test_map_ctrl_c_insert() it('Ctrl-c works in Insert mode', function() -- Mapping of ctrl-c in insert mode command('set cpo-=< cpo-=k') @@ -41,6 +44,7 @@ describe('mapping', function() ]]) end) + -- oldtest: Test_map_ctrl_c_visual() it('Ctrl-c works in Visual mode', function() command([[vnoremap :$put ='vmap works']]) feed('GV') @@ -83,6 +87,7 @@ describe('mapping', function() +]]) end) + -- oldtest: Test_map_feedkeys() it('feedkeys', function() insert([[ a b c d @@ -100,6 +105,7 @@ describe('mapping', function() ]]) end) + -- oldtest: Test_map_cursor() it('i_CTRL-G_U', function() -- U works only within a single line command('imapclear') @@ -128,7 +134,8 @@ describe('mapping', function() ]]) end) - it('dragging starts Select mode even if coming from mapping vim-patch:8.2.4806', function() + -- oldtest: Test_mouse_drag_mapped_start_select() + it('dragging starts Select mode even if coming from mapping', function() command('set mouse=a') command('set selectmode=mouse') @@ -141,7 +148,8 @@ describe('mapping', function() eq('s', eval('mode()')) end) - it(' mapping in Insert mode works correctly vim-patch:8.2.4692', function() + -- oldtest: Test_mouse_drag_insert_map() + it(' mapping in Insert mode works correctly', function() command('set mouse=a') command('inoremap let g:dragged = 1') @@ -165,7 +173,8 @@ describe('mapping', function() eq('n', eval('mode()')) end) - it('timeout works after an mapping is triggered on timeout vim-patch:8.1.0052', function() + -- oldtest: Test_map_after_timed_out_nop() + it('timeout works after an mapping is triggered on timeout', function() command('set timeout timeoutlen=400') command('inoremap ab TEST') command('inoremap a ') @@ -181,4 +190,65 @@ describe('mapping', function() feed('b') expect('TEST') end) + + -- oldtest: Test_showcmd_part_map() + it("'showcmd' with a partial mapping", function() + local screen = Screen.new(60, 6) + screen:attach() + exec([[ + set notimeout showcmd + nnoremap ,a + nnoremap ;a + nnoremap Àa + nnoremap Ëa + nnoremap βa + nnoremap ωa + nnoremap …a + nnoremap a + ]]) + + for _, c in ipairs({ ',', ';', 'À', 'Ë', 'β', 'ω', '…' }) do + feed(c) + screen:expect(([[ + ^ | + {1:~ }|*4 + %s | + ]]):format(c)) + feed('') + command('echo') + screen:expect([[ + ^ | + {1:~ }|*4 + | + ]]) + end + + feed('\23') + screen:expect([[ + ^ | + {1:~ }|*4 + ^W | + ]]) + feed('') + command('echo') + screen:expect([[ + ^ | + {1:~ }|*4 + | + ]]) + + feed('') + screen:expect([[ + ^ | + {1:~ }|*4 + ^W | + ]]) + feed('') + command('echo') + screen:expect([[ + ^ | + {1:~ }|*4 + | + ]]) + end) end) diff --git a/test/old/testdir/test_mapping.vim b/test/old/testdir/test_mapping.vim index 623228b347..811a260238 100644 --- a/test/old/testdir/test_mapping.vim +++ b/test/old/testdir/test_mapping.vim @@ -1693,7 +1693,7 @@ func Test_map_after_timed_out_nop() inoremap ab TEST inoremap a END - call writefile(lines, 'Xtest_map_after_timed_out_nop') + call writefile(lines, 'Xtest_map_after_timed_out_nop', 'D') let buf = RunVimInTerminal('-S Xtest_map_after_timed_out_nop', #{rows: 6}) " Enter Insert mode @@ -1710,7 +1710,48 @@ func Test_map_after_timed_out_nop() " clean up call StopVimInTerminal(buf) - call delete('Xtest_map_after_timed_out_nop') +endfunc + +" Test 'showcmd' behavior with a partial mapping +func Test_showcmd_part_map() + CheckRunVimInTerminal + + let lines =<< trim eval END + set notimeout showcmd + nnoremap ,a + nnoremap ;a + nnoremap Àa + nnoremap Ëa + nnoremap βa + nnoremap ωa + nnoremap …a + nnoremap a + END + call writefile(lines, 'Xtest_showcmd_part_map', 'D') + let buf = RunVimInTerminal('-S Xtest_showcmd_part_map', #{rows: 6}) + + call term_sendkeys(buf, ":set noruler | echo\") + call WaitForAssert({-> assert_equal('', term_getline(buf, 6))}) + + for c in [',', ';', 'À', 'Ë', 'β', 'ω', '…'] + call term_sendkeys(buf, c) + call WaitForAssert({-> assert_equal(c, trim(term_getline(buf, 6)))}) + call term_sendkeys(buf, "\:echo\") + call WaitForAssert({-> assert_equal('', term_getline(buf, 6))}) + endfor + + call term_sendkeys(buf, "\") + call WaitForAssert({-> assert_equal('^W', trim(term_getline(buf, 6)))}) + call term_sendkeys(buf, "\:echo\") + call WaitForAssert({-> assert_equal('', term_getline(buf, 6))}) + + " Use feedkeys() as terminal buffer cannot forward this + call term_sendkeys(buf, ':call feedkeys("\<*C-W>", "m")' .. " | echo\") + call WaitForAssert({-> assert_equal('^W', trim(term_getline(buf, 6)))}) + call term_sendkeys(buf, "\:echo\") + call WaitForAssert({-> assert_equal('', term_getline(buf, 6))}) + + call StopVimInTerminal(buf) endfunc func Test_using_past_typeahead() -- cgit