aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/mark.c
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2019-03-14 06:23:05 -0400
committerJustin M. Keyes <justinkz@gmail.com>2019-03-14 11:23:05 +0100
commitcbe4377fde315123fea9928371bd2a62f32d90e4 (patch)
tree0340b11819e268b74955327608556f58ca162a83 /src/nvim/mark.c
parent907b4803500e3321b0996807d75d85646a6720e2 (diff)
downloadrneovim-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/mark.c')
-rw-r--r--src/nvim/mark.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/nvim/mark.c b/src/nvim/mark.c
index 602648c27c..af404c354b 100644
--- a/src/nvim/mark.c
+++ b/src/nvim/mark.c
@@ -1069,19 +1069,24 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2,
{ \
posp->lnum += lnum_amount; \
assert(col_amount > INT_MIN && col_amount <= INT_MAX); \
- if (col_amount < 0 && posp->col <= (colnr_T)-col_amount) \
+ if (col_amount < 0 && posp->col <= (colnr_T)-col_amount) { \
posp->col = 0; \
- else \
+ } else if (posp->col < spaces_removed) { \
+ posp->col = (int)col_amount + spaces_removed; \
+ } else { \
posp->col += (colnr_T)col_amount; \
+ } \
} \
}
-/*
- * 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.
- */
-void mark_col_adjust(linenr_T lnum, colnr_T mincol, long lnum_amount, long col_amount)
+// 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,
+ int spaces_removed)
{
int i;
int fnum = curbuf->b_fnum;