]> granicus.if.org Git - vim/commitdiff
patch 8.1.1988: :startinsert! does not work the same way as "A" v8.1.1988
authorBram Moolenaar <Bram@vim.org>
Thu, 5 Sep 2019 19:29:01 +0000 (21:29 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 5 Sep 2019 19:29:01 +0000 (21:29 +0200)
Problem:    :startinsert! does not work the same way as "A".
Solution:   Use the same code to move the cursor. (closes #4896)

src/ex_docmd.c
src/normal.c
src/proto/normal.pro
src/testdir/test_edit.vim
src/version.c

index ef86ae5fc5ffd52a756a8362ad03db1d3c4d0579..0e0e1b8794afe44bd92b8d4b790a4a4d06a256fd 100644 (file)
@@ -7596,16 +7596,14 @@ ex_startinsert(exarg_T *eap)
 {
     if (eap->forceit)
     {
-       /* cursor line can be zero on startup */
+       // cursor line can be zero on startup
        if (!curwin->w_cursor.lnum)
            curwin->w_cursor.lnum = 1;
-       coladvance((colnr_T)MAXCOL);
-       curwin->w_curswant = MAXCOL;
-       curwin->w_set_curswant = FALSE;
+       set_cursor_for_append_to_line();
     }
 
-    /* Ignore the command when already in Insert mode.  Inserting an
-     * expression register that invokes a function can do this. */
+    // Ignore the command when already in Insert mode.  Inserting an
+    // expression register that invokes a function can do this.
     if (State & INSERT)
        return;
 
@@ -7620,7 +7618,7 @@ ex_startinsert(exarg_T *eap)
     {
        if (eap->cmdidx == CMD_startinsert)
            restart_edit = 'i';
-       curwin->w_curswant = 0;     /* avoid MAXCOL */
+       curwin->w_curswant = 0;     // avoid MAXCOL
     }
 }
 
index 1db1d16abb4d626a42a088c51a8940fbcfa5fee8..7abd3fc993576ecbb11bb18e18c0a23cf02250e6 100644 (file)
@@ -8897,6 +8897,27 @@ nv_esc(cmdarg_T *cap)
        restart_edit = 'a';
 }
 
+/*
+ * Move the cursor for the "A" command.
+ */
+    void
+set_cursor_for_append_to_line(void)
+{
+    curwin->w_set_curswant = TRUE;
+    if (ve_flags == VE_ALL)
+    {
+       int save_State = State;
+
+       /* Pretend Insert mode here to allow the cursor on the
+        * character past the end of the line */
+       State = INSERT;
+       coladvance((colnr_T)MAXCOL);
+       State = save_State;
+    }
+    else
+       curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor());
+}
+
 /*
  * Handle "A", "a", "I", "i" and <Insert> commands.
  * Also handle K_PS, start bracketed paste.
@@ -8983,19 +9004,7 @@ nv_edit(cmdarg_T *cap)
        switch (cap->cmdchar)
        {
            case 'A':   /* "A"ppend after the line */
-               curwin->w_set_curswant = TRUE;
-               if (ve_flags == VE_ALL)
-               {
-                   int save_State = State;
-
-                   /* Pretend Insert mode here to allow the cursor on the
-                    * character past the end of the line */
-                   State = INSERT;
-                   coladvance((colnr_T)MAXCOL);
-                   State = save_State;
-               }
-               else
-                   curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor());
+               set_cursor_for_append_to_line();
                break;
 
            case 'I':   /* "I"nsert before the first non-blank */
index cc4bf7dfc9cb0e14239e0fd2826423473199a0b0..dd62226098ef76c13f34af0acc6715ef0d192a64 100644 (file)
@@ -23,4 +23,5 @@ void do_nv_ident(int c1, int c2);
 int get_visual_text(cmdarg_T *cap, char_u **pp, int *lenp);
 void start_selection(void);
 void may_start_select(int c);
+void set_cursor_for_append_to_line(void);
 /* vim: set ft=c : */
index 799642d3db95abcd5b0e005672e68718ee75dbdd..6ee5848109160ce15f4ace873bd1dcc7973f2002 100644 (file)
@@ -1480,3 +1480,18 @@ func Test_edit_special_chars()
 
   close!
 endfunc
+
+func Test_edit_startinsert()
+  new
+  set backspace+=start
+  call setline(1, 'foobar')
+  call feedkeys("A\<C-U>\<Esc>", 'xt')
+  call assert_equal('', getline(1))
+
+  call setline(1, 'foobar')
+  call feedkeys(":startinsert!\<CR>\<C-U>\<Esc>", 'xt')
+  call assert_equal('', getline(1))
+
+  set backspace&
+  bwipe!
+endfunc
index 420d1ff5255d320175d075392d7b7912581e66e7..52e12ee7469866f3c5f783ad969e97ae6ac0fc8b 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1988,
 /**/
     1987,
 /**/