1
0
forked from aniani/vim

patch 9.1.1221: Wrong cursor pos when leaving Insert mode just after 'autoindent'

Problem:  Wrong cursor position and '^' mark when leaving Insert mode
          just after 'autoindent' and cursor on last char of line.
Solution: Don't move cursor to NUL when it wasn't moved to the left
          (zeertzjq).

fixes: #15581
related: neovim/neovim#30165 neovim/neovim#32943
closes: #16922

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq
2025-03-18 20:41:24 +01:00
committed by Christian Brabandt
parent 18a6853a76
commit a3a7d10bfb
3 changed files with 62 additions and 1 deletions

View File

@@ -2512,6 +2512,7 @@ stop_insert(
&& end_insert_pos->lnum <= curbuf->b_ml.ml_line_count)
{
pos_T tpos = curwin->w_cursor;
colnr_T prev_col = end_insert_pos->col;
curwin->w_cursor = *end_insert_pos;
check_cursor_col(); // make sure it is not past the line
@@ -2527,7 +2528,7 @@ stop_insert(
}
if (curwin->w_cursor.lnum != tpos.lnum)
curwin->w_cursor = tpos;
else
else if (curwin->w_cursor.col < prev_col)
{
// reset tpos, could have been invalidated in the loop above
tpos = curwin->w_cursor;