Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
15325:95f2bbb27172 | 15326:fe428bee74b3 |
---|---|
4705 * column. This is not Vi compatible, but Vi deletes the marks, thus that | 4705 * column. This is not Vi compatible, but Vi deletes the marks, thus that |
4706 * should not really be a problem. | 4706 * should not really be a problem. |
4707 */ | 4707 */ |
4708 for (t = count - 1; ; --t) | 4708 for (t = count - 1; ; --t) |
4709 { | 4709 { |
4710 int spaces_removed; | |
4711 | |
4710 cend -= currsize; | 4712 cend -= currsize; |
4711 mch_memmove(cend, curr, (size_t)currsize); | 4713 mch_memmove(cend, curr, (size_t)currsize); |
4712 if (spaces[t] > 0) | 4714 if (spaces[t] > 0) |
4713 { | 4715 { |
4714 cend -= spaces[t]; | 4716 cend -= spaces[t]; |
4715 vim_memset(cend, ' ', (size_t)(spaces[t])); | 4717 vim_memset(cend, ' ', (size_t)(spaces[t])); |
4716 } | 4718 } |
4719 | |
4720 // If deleting more spaces than adding, the cursor moves no more than | |
4721 // what is added if it is inside these spaces. | |
4722 spaces_removed = (curr - curr_start) - spaces[t]; | |
4723 | |
4717 mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, (linenr_T)-t, | 4724 mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, (linenr_T)-t, |
4718 (long)(cend - newp + spaces[t] - (curr - curr_start))); | 4725 (long)(cend - newp - spaces_removed), spaces_removed); |
4719 if (t == 0) | 4726 if (t == 0) |
4720 break; | 4727 break; |
4721 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1)); | 4728 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1)); |
4722 #if defined(FEAT_COMMENTS) || defined(PROTO) | 4729 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4723 if (remove_comments) | 4730 if (remove_comments) |
5223 #ifdef FEAT_COMMENTS | 5230 #ifdef FEAT_COMMENTS |
5224 if (next_leader_len > 0) | 5231 if (next_leader_len > 0) |
5225 { | 5232 { |
5226 (void)del_bytes((long)next_leader_len, FALSE, FALSE); | 5233 (void)del_bytes((long)next_leader_len, FALSE, FALSE); |
5227 mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, | 5234 mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, |
5228 (long)-next_leader_len); | 5235 (long)-next_leader_len, 0); |
5229 } else | 5236 } else |
5230 #endif | 5237 #endif |
5231 if (second_indent > 0) /* the "leader" for FO_Q_SECOND */ | 5238 if (second_indent > 0) /* the "leader" for FO_Q_SECOND */ |
5232 { | 5239 { |
5233 int indent = getwhitecols_curline(); | 5240 int indent = getwhitecols_curline(); |
5234 | 5241 |
5235 if (indent > 0) | 5242 if (indent > 0) |
5236 { | 5243 { |
5237 (void)del_bytes(indent, FALSE, FALSE); | 5244 (void)del_bytes(indent, FALSE, FALSE); |
5238 mark_col_adjust(curwin->w_cursor.lnum, | 5245 mark_col_adjust(curwin->w_cursor.lnum, |
5239 (colnr_T)0, 0L, (long)-indent); | 5246 (colnr_T)0, 0L, (long)-indent, 0); |
5240 } | 5247 } |
5241 } | 5248 } |
5242 curwin->w_cursor.lnum--; | 5249 curwin->w_cursor.lnum--; |
5243 if (do_join(2, TRUE, FALSE, FALSE, FALSE) == FAIL) | 5250 if (do_join(2, TRUE, FALSE, FALSE, FALSE) == FAIL) |
5244 { | 5251 { |