vim-patch:9.1.1221: Wrong cursor pos when leaving Insert mode just after 'autoindent' (#32976)

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: vim/vim#15581
related: neovim/neovim#30165 neovim/neovim#32943
closes: vim/vim#16922

a3a7d10bfb
This commit is contained in:
zeertzjq
2025-03-19 07:34:02 +08:00
committed by GitHub
parent 4d83649d10
commit 430d12a4fd
2 changed files with 60 additions and 1 deletions

View File

@@ -2390,6 +2390,7 @@ static void stop_insert(pos_T *end_insert_pos, int esc, int nomove)
end_insert_pos->lnum))
&& 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(curwin); // make sure it is not past the line
@@ -2407,7 +2408,7 @@ static void stop_insert(pos_T *end_insert_pos, int esc, int nomove)
}
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;
tpos.col++;