diff src/mark.c @ 15326:fe428bee74b3 v8.1.0671

patch 8.1.0671: cursor in the wrong column after auto-formatting commit https://github.com/vim/vim/commit/e1e714ef0d1f4bb8b1712795e9106e3b4ff4c7bd Author: Bram Moolenaar <Bram@vim.org> Date: Mon Dec 31 23:58:24 2018 +0100 patch 8.1.0671: cursor in the wrong column after auto-formatting Problem: Cursor in the wrong column after auto-formatting. Solution: Check for deleting more spaces than adding. (closes https://github.com/vim/vim/issues/3748)
author Bram Moolenaar <Bram@vim.org>
date Tue, 01 Jan 2019 00:00:07 +0100
parents c5ec5ddbe814
children 55ccc2d353bd
line wrap: on
line diff
--- a/src/mark.c
+++ b/src/mark.c
@@ -1211,6 +1211,8 @@ mark_adjust_internal(
 	    posp->lnum += lnum_amount; \
 	    if (col_amount < 0 && posp->col <= (colnr_T)-col_amount) \
 		posp->col = 0; \
+	    else if (posp->col < spaces_removed) \
+		posp->col = col_amount + spaces_removed; \
 	    else \
 		posp->col += col_amount; \
 	} \
@@ -1220,13 +1222,16 @@ mark_adjust_internal(
  * Adjust marks in line "lnum" at column "mincol" and further: add
  * "lnum_amount" to the line number and add "col_amount" to the column
  * position.
+ * "spaces_removed" is the number of spaces that were removed, matters when the
+ * cursor is inside them.
  */
     void
 mark_col_adjust(
     linenr_T	lnum,
     colnr_T	mincol,
     long	lnum_amount,
-    long	col_amount)
+    long	col_amount,
+    int		spaces_removed)
 {
     int		i;
     int		fnum = curbuf->b_fnum;