]> granicus.if.org Git - vim/commitdiff
patch 8.2.4711: when 'insermode' is set :edit from <Cmd> mapping misbehaves v8.2.4711
authorzeertzjq <zeertzjq@outlook.com>
Fri, 8 Apr 2022 10:56:14 +0000 (11:56 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 8 Apr 2022 10:56:14 +0000 (11:56 +0100)
Problem:    When 'insermode' is set :edit from <Cmd> mapping misbehaves.
Solution:   Don't set "need_start_insertmode" when already in Insert mode.
            (closes #10116)

src/ex_cmds.c
src/testdir/test_edit.vim
src/version.c

index 8cdac4b74ea6d424defad51af594008d9999c0b9..50829be70b8f4d67b6851b85659a397c15eb7619 100644 (file)
@@ -3182,7 +3182,7 @@ do_ecmd(
        redraw_curbuf_later(NOT_VALID); // redraw this buffer later
     }
 
-    if (p_im)
+    if (p_im && (State & INSERT) == 0)
        need_start_insertmode = TRUE;
 
 #ifdef FEAT_AUTOCHDIR
index a96a95bd3ae4a5f83e12ade37774167c181c6458..9ed899d8381c69b7b6af0694d5156bda8068381b 100644 (file)
@@ -1840,6 +1840,29 @@ func Test_edit_file_no_read_perm()
   call delete('Xfile')
 endfunc
 
+" Using :edit without leaving 'insertmode' should not cause Insert mode to be
+" re-entered immediately after <C-L>
+func Test_edit_insertmode_ex_edit()
+  CheckRunVimInTerminal
+
+  let lines =<< trim END
+    set insertmode noruler
+    inoremap <C-B> <Cmd>edit Xfoo<CR>
+  END
+  call writefile(lines, 'Xtest_edit_insertmode_ex_edit')
+
+  let buf = RunVimInTerminal('-S Xtest_edit_insertmode_ex_edit', #{rows: 6})
+  call TermWait(buf, 50)
+  call assert_match('^-- INSERT --\s*$', term_getline(buf, 6))
+  call term_sendkeys(buf, "\<C-B>\<C-L>")
+  call TermWait(buf, 50)
+  call assert_notmatch('^-- INSERT --\s*$', term_getline(buf, 6))
+
+  " clean up
+  call StopVimInTerminal(buf)
+  call delete('Xtest_edit_insertmode_ex_edit')
+endfunc
+
 " Pressing escape in 'insertmode' should beep
 func Test_edit_insertmode_esc_beeps()
   new
index 956100304bd9e2724429dc716d46f284407bb37e..54efff406af0d79e612f05b7fcbbb691181eb558 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4711,
 /**/
     4710,
 /**/