Patch 8.1.1988
Problem: :startinsert! does not work the same way as "A".
Solution: Use the same code to move the cursor. (closes #4896)
Files: src/ex_docmd.c, src/normal.c, src/proto/normal.pro,
src/testdir/test_edit.vim
*** ../vim-8.1.1987/src/ex_docmd.c 2019-09-04 15:54:23.916359692 +0200
--- src/ex_docmd.c 2019-09-05 21:28:20.399274671 +0200
***************
*** 7596,7611 ****
{
if (eap->forceit)
{
! /* 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;
}
! /* Ignore the command when already in Insert mode. Inserting an
! * expression register that invokes a function can do this. */
if (State & INSERT)
return;
--- 7596,7609 ----
{
if (eap->forceit)
{
! // cursor line can be zero on startup
if (!curwin->w_cursor.lnum)
curwin->w_cursor.lnum = 1;
! 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.
if (State & INSERT)
return;
***************
*** 7620,7626 ****
{
if (eap->cmdidx == CMD_startinsert)
restart_edit = 'i';
! curwin->w_curswant = 0; /* avoid MAXCOL */
}
}
--- 7618,7624 ----
{
if (eap->cmdidx == CMD_startinsert)
restart_edit = 'i';
! curwin->w_curswant = 0; // avoid MAXCOL
}
}
*** ../vim-8.1.1987/src/normal.c 2019-08-19 22:48:27.173038748 +0200
--- src/normal.c 2019-09-05 20:58:55.540783410 +0200
***************
*** 8898,8903 ****
--- 8898,8924 ----
}
/*
+ * 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,9001 ****
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());
break;
case 'I': /* "I"nsert before the first non-blank */
--- 9004,9010 ----
switch (cap->cmdchar)
{
case 'A': /* "A"ppend after the line */
! set_cursor_for_append_to_line();
break;
case 'I': /* "I"nsert before the first non-blank */
*** ../vim-8.1.1987/src/proto/normal.pro 2019-07-09 23:22:11.570422512
+0200
--- src/proto/normal.pro 2019-09-05 20:58:59.508775002 +0200
***************
*** 23,26 ****
--- 23,27 ----
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 : */
*** ../vim-8.1.1987/src/testdir/test_edit.vim 2019-08-24 22:58:08.307264136
+0200
--- src/testdir/test_edit.vim 2019-09-05 21:27:28.339433008 +0200
***************
*** 1480,1482 ****
--- 1480,1497 ----
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
*** ../vim-8.1.1987/src/version.c 2019-09-04 22:28:53.061026888 +0200
--- src/version.c 2019-09-05 21:25:24.927832358 +0200
***************
*** 759,760 ****
--- 759,762 ----
{ /* Add new patch number below this line */
+ /**/
+ 1988,
/**/
--
hundred-and-one symptoms of being an internet addict:
191. You rate eating establishments not by the quality of the food,
but by the availability of electrical outlets for your PowerBook.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/201909051929.x85JTQO9013335%40masaka.moolenaar.net.