diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2019-03-14 06:23:05 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-03-14 11:23:05 +0100 |
commit | cbe4377fde315123fea9928371bd2a62f32d90e4 (patch) | |
tree | 0340b11819e268b74955327608556f58ca162a83 /src/nvim/ops.c | |
parent | 907b4803500e3321b0996807d75d85646a6720e2 (diff) | |
download | rneovim-cbe4377fde315123fea9928371bd2a62f32d90e4.tar.gz rneovim-cbe4377fde315123fea9928371bd2a62f32d90e4.tar.bz2 rneovim-cbe4377fde315123fea9928371bd2a62f32d90e4.zip |
vim-patch:8.1.0671: cursor in wrong column after auto-format #9729
Problem: Cursor in the wrong column after auto-formatting.
Solution: Check for deleting more spaces than adding. (closes vim/vim#3748)
https://github.com/vim/vim/commit/e1e714ef0d1f4bb8b1712795e9106e3b4ff4c7bd
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r-- | src/nvim/ops.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 6a3a404454..02ec3aad31 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3707,10 +3707,16 @@ int do_join(size_t count, cend -= spaces[t]; 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. + const int spaces_removed = (int)((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))); - if (t == 0) + (long)(cend - newp - spaces_removed), spaces_removed); + if (t == 0) { break; + } curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1)); if (remove_comments) curr += comments[t - 1]; @@ -4138,14 +4144,14 @@ format_lines ( if (next_leader_len > 0) { (void)del_bytes(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 if (second_indent > 0) { // the "leader" for FO_Q_SECOND int indent = (int)getwhitecols_curline(); if (indent > 0) { (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--; |