Mercurial > vim
diff src/ops.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 | 3a94f7918980 |
children | b55b89692fd2 |
line wrap: on
line diff
--- 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--;