mirror of
https://github.com/neovim/neovim.git
synced 2025-09-19 09:48:19 +00:00
vim-patch:8.1.1988: :startinsert! does not work the same way as "A"
Problem: :startinsert! does not work the same way as "A".
Solution: Use the same code to move the cursor. (closes vim/vim#4896)
8d3b51084a
This commit is contained in:
@@ -8305,15 +8305,14 @@ static void ex_startinsert(exarg_T *eap)
|
|||||||
if (!curwin->w_cursor.lnum) {
|
if (!curwin->w_cursor.lnum) {
|
||||||
curwin->w_cursor.lnum = 1;
|
curwin->w_cursor.lnum = 1;
|
||||||
}
|
}
|
||||||
coladvance((colnr_T)MAXCOL);
|
set_cursor_for_append_to_line();
|
||||||
curwin->w_curswant = MAXCOL;
|
|
||||||
curwin->w_set_curswant = FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ignore the command when already in Insert mode. Inserting an
|
// Ignore the command when already in Insert mode. Inserting an
|
||||||
* expression register that invokes a function can do this. */
|
// expression register that invokes a function can do this.
|
||||||
if (State & INSERT)
|
if (State & INSERT) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (eap->cmdidx == CMD_startinsert)
|
if (eap->cmdidx == CMD_startinsert)
|
||||||
restart_edit = 'a';
|
restart_edit = 'a';
|
||||||
@@ -8325,7 +8324,7 @@ static void ex_startinsert(exarg_T *eap)
|
|||||||
if (!eap->forceit) {
|
if (!eap->forceit) {
|
||||||
if (eap->cmdidx == CMD_startinsert)
|
if (eap->cmdidx == CMD_startinsert)
|
||||||
restart_edit = 'i';
|
restart_edit = 'i';
|
||||||
curwin->w_curswant = 0; /* avoid MAXCOL */
|
curwin->w_curswant = 0; // avoid MAXCOL
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIsual_active) {
|
if (VIsual_active) {
|
||||||
|
@@ -7508,6 +7508,23 @@ static void nv_esc(cmdarg_T *cap)
|
|||||||
restart_edit = 'a';
|
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) {
|
||||||
|
const 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(get_cursor_pos_ptr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Handle "A", "a", "I", "i" and <Insert> commands.
|
/// Handle "A", "a", "I", "i" and <Insert> commands.
|
||||||
static void nv_edit(cmdarg_T *cap)
|
static void nv_edit(cmdarg_T *cap)
|
||||||
{
|
{
|
||||||
@@ -7529,18 +7546,8 @@ static void nv_edit(cmdarg_T *cap)
|
|||||||
clearop(cap->oap);
|
clearop(cap->oap);
|
||||||
} else if (!checkclearopq(cap->oap)) {
|
} else if (!checkclearopq(cap->oap)) {
|
||||||
switch (cap->cmdchar) {
|
switch (cap->cmdchar) {
|
||||||
case 'A': /* "A"ppend after the line */
|
case 'A': // "A"ppend after the line
|
||||||
curwin->w_set_curswant = true;
|
set_cursor_for_append_to_line();
|
||||||
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(get_cursor_pos_ptr());
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'I': /* "I"nsert before the first non-blank */
|
case 'I': /* "I"nsert before the first non-blank */
|
||||||
|
@@ -1484,3 +1484,18 @@ func Test_edit_special_chars()
|
|||||||
|
|
||||||
close!
|
close!
|
||||||
endfunc
|
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
|
||||||
|
Reference in New Issue
Block a user