]> granicus.if.org Git - vim/commitdiff
patch 8.2.4837: modifiers not simplified when timed out v8.2.4837
authorzeertzjq <zeertzjq@outlook.com>
Thu, 28 Apr 2022 13:10:01 +0000 (14:10 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 28 Apr 2022 13:10:01 +0000 (14:10 +0100)
Problem:    Modifiers not simplified when timed out or using feedkeys() with
            'n" flag.
Solution:   Adjust how mapped flag and timeout are used. (closes #10305)

src/getchar.c
src/testdir/test_paste.vim
src/testdir/test_termcodes.vim
src/version.c

index e6879c60d97572109a5b9d2dc5cfb1e83bb4e4e6..2b1bbde4b0da20701742afd4111535dcf98d857a 100644 (file)
@@ -2699,17 +2699,19 @@ handle_mapping(
         * - and not an ESC sequence, not in insert mode or p_ek is on,
         * - and when not timed out,
         */
-       if ((no_mapping == 0 || allow_keys != 0)
-               && (typebuf.tb_maplen == 0
+       if (no_mapping == 0 || allow_keys != 0)
+       {
+           if ((typebuf.tb_maplen == 0
                    || (p_remap && typebuf.tb_noremap[
                                                    typebuf.tb_off] == RM_YES))
                && !*timedout)
-       {
-           keylen = check_termcode(max_mlen + 1, NULL, 0, NULL);
+               keylen = check_termcode(max_mlen + 1, NULL, 0, NULL);
+           else
+               keylen = 0;
 
            // If no termcode matched but 'pastetoggle' matched partially
            // it's like an incomplete key sequence.
-           if (keylen == 0 && save_keylen == KEYLEN_PART_KEY)
+           if (keylen == 0 && save_keylen == KEYLEN_PART_KEY && !*timedout)
                keylen = KEYLEN_PART_KEY;
 
            // If no termcode matched, try to include the modifier into the
index a59e1286916ef7baae079282c785585e6115eaaf..17ac9e4d5022332ca4a0f8e6182426c575476a52 100644 (file)
@@ -2,6 +2,7 @@
 
 " Bracketed paste only works with "xterm".  Not in GUI or Windows console.
 source check.vim
+source term_util.vim
 CheckNotMSWindows
 CheckNotGui
 
@@ -217,6 +218,69 @@ func Test_pastetoggle()
   bwipe!
 endfunc
 
+func Test_pastetoggle_timeout_no_typed_after_mapped()
+  CheckRunVimInTerminal
+
+  let lines =<< trim END
+    set pastetoggle=abc
+    set ttimeoutlen=10000
+    imap d a
+  END
+  call writefile(lines, 'Xpastetoggle_no_typed_after_mapped.vim')
+  let buf = RunVimInTerminal('-S Xpastetoggle_no_typed_after_mapped.vim', #{rows: 8})
+  call TermWait(buf)
+  call term_sendkeys(buf, ":call feedkeys('id', 't')\<CR>")
+  call term_wait(buf, 200)
+  call term_sendkeys(buf, 'bc')
+  " 'ttimeoutlen' should NOT apply
+  call WaitForAssert({-> assert_match('^-- INSERT --', term_getline(buf, 8))})
+
+  call StopVimInTerminal(buf)
+  call delete('Xpastetoggle_no_typed_after_mapped.vim')
+endfunc
+
+func Test_pastetoggle_timeout_typed_after_mapped()
+  CheckRunVimInTerminal
+
+  let lines =<< trim END
+    set pastetoggle=abc
+    set ttimeoutlen=10000
+    imap d a
+  END
+  call writefile(lines, 'Xpastetoggle_typed_after_mapped.vim')
+  let buf = RunVimInTerminal('-S Xpastetoggle_typed_after_mapped.vim', #{rows: 8})
+  call TermWait(buf)
+  call term_sendkeys(buf, ":call feedkeys('idb', 't')\<CR>")
+  call term_wait(buf, 200)
+  call term_sendkeys(buf, 'c')
+  " 'ttimeoutlen' should apply
+  call WaitForAssert({-> assert_match('^-- INSERT (paste) --', term_getline(buf, 8))})
+
+  call StopVimInTerminal(buf)
+  call delete('Xpastetoggle_typed_after_mapped.vim')
+endfunc
+
+func Test_pastetoggle_timeout_typed_after_noremap()
+  CheckRunVimInTerminal
+
+  let lines =<< trim END
+    set pastetoggle=abc
+    set ttimeoutlen=10000
+    inoremap d a
+  END
+  call writefile(lines, 'Xpastetoggle_typed_after_noremap.vim')
+  let buf = RunVimInTerminal('-S Xpastetoggle_typed_after_noremap.vim', #{rows: 8})
+  call TermWait(buf)
+  call term_sendkeys(buf, ":call feedkeys('idb', 't')\<CR>")
+  call term_wait(buf, 200)
+  call term_sendkeys(buf, 'c')
+  " 'ttimeoutlen' should apply
+  call WaitForAssert({-> assert_match('^-- INSERT (paste) --', term_getline(buf, 8))})
+
+  call StopVimInTerminal(buf)
+  call delete('Xpastetoggle_typed_after_noremap.vim')
+endfunc
+
 " Test for restoring option values when 'paste' is disabled
 func Test_paste_opt_restore()
   set autoindent expandtab ruler showmatch
index c9b0c7b735b67f3f400aff0f08982e4f81778584..87c04745a10ededa1c467d6cebba32a3a5e260d3 100644 (file)
@@ -2444,5 +2444,21 @@ func Test_simplify_ctrl_at()
   bw!
 endfunc
 
+func Test_simplify_noremap()
+  call feedkeys("i\<*C-M>", 'nx')
+  call assert_equal('', getline(1))
+  call assert_equal([0, 2, 1, 0, 1], getcurpos())
+  bw!
+endfunc
+
+func Test_simplify_timedout()
+  inoremap <C-M>a b
+  call feedkeys("i\<*C-M>", 'xt')
+  call assert_equal('', getline(1))
+  call assert_equal([0, 2, 1, 0, 1], getcurpos())
+  iunmap <C-M>a
+  bw!
+endfunc
+
 
 " vim: shiftwidth=2 sts=2 expandtab
index 53afc37768219759cfe516ad9fb9d1c8c0448877..2fa8992d775812f7ae97ca47925faae32b9a9366 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4837,
 /**/
     4836,
 /**/