summaryrefslogtreecommitdiffstats
path: root/src/ops.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-12-31 23:58:24 +0100
committerBram Moolenaar <Bram@vim.org>2018-12-31 23:58:24 +0100
commite1e714ef0d1f4bb8b1712795e9106e3b4ff4c7bd (patch)
treea8140991365c6a83af9d501ef7e471dc0c9160d4 /src/ops.c
parent3d631cb0b34b03c7bdf45ad852d3644c7cf62743 (diff)
patch 8.1.0671: cursor in the wrong column after auto-formattingv8.1.0671
Problem: Cursor in the wrong column after auto-formatting. Solution: Check for deleting more spaces than adding. (closes #3748)
Diffstat (limited to 'src/ops.c')
-rw-r--r--src/ops.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/ops.c b/src/ops.c
index 004d5093c2..58f201f290 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -4707,6 +4707,8 @@ do_join(
*/
for (t = count - 1; ; --t)
{
+ int spaces_removed;
+
cend -= currsize;
mch_memmove(cend, curr, (size_t)currsize);
if (spaces[t] > 0)
@@ -4714,8 +4716,13 @@ do_join(
cend -= spaces[t];
vim_memset(cend, ' ', (size_t)(spaces[t]));
}
+
+ // If deleting more spaces than adding, the cursor moves no more than
+ // what is added if it is inside these spaces.
+ spaces_removed = (curr - curr_start) - spaces[t];
+
mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, (linenr_T)-t,
- (long)(cend - newp + spaces[t] - (curr - curr_start)));
+ (long)(cend - newp - spaces_removed), spaces_removed);
if (t == 0)
break;
curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1));
@@ -5225,7 +5232,7 @@ format_lines(
{
(void)del_bytes((long)next_leader_len, FALSE, FALSE);
mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L,
- (long)-next_leader_len);
+ (long)-next_leader_len, 0);
} else
#endif
if (second_indent > 0) /* the "leader" for FO_Q_SECOND */
@@ -5236,7 +5243,7 @@ format_lines(
{
(void)del_bytes(indent, FALSE, FALSE);
mark_col_adjust(curwin->w_cursor.lnum,
- (colnr_T)0, 0L, (long)-indent);
+ (colnr_T)0, 0L, (long)-indent, 0);
}
}
curwin->w_cursor.lnum--;