aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/indent.c
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-11-02 01:37:05 -0500
committerGitHub <noreply@github.com>2020-11-02 01:37:05 -0500
commit6224ec3d4a672a9beb7522a34e61fa3b335bf070 (patch)
treeffa272383fa6ad9a6deb7dc3b76ec14103a50a40 /src/nvim/indent.c
parent90f3a8ba291fb0583ab6b0bd33129fdd45df1dab (diff)
parent4b65e4aeab16c1700a3c01a643e439a5000d932e (diff)
downloadrneovim-6224ec3d4a672a9beb7522a34e61fa3b335bf070.tar.gz
rneovim-6224ec3d4a672a9beb7522a34e61fa3b335bf070.tar.bz2
rneovim-6224ec3d4a672a9beb7522a34e61fa3b335bf070.zip
Merge pull request #13204 from janlazo/vim-8.2.1938
vim-patch:8.1.{2030,2063},8.2.{864,1086,1938}
Diffstat (limited to 'src/nvim/indent.c')
-rw-r--r--src/nvim/indent.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/nvim/indent.c b/src/nvim/indent.c
index bb0fdfec01..9e6693afdf 100644
--- a/src/nvim/indent.c
+++ b/src/nvim/indent.c
@@ -295,13 +295,17 @@ int set_indent(int size, int flags)
// Replace the line (unless undo fails).
if (!(flags & SIN_UNDO) || (u_savesub(curwin->w_cursor.lnum) == OK)) {
+ const colnr_T old_offset = (colnr_T)(p - oldline);
+ const colnr_T new_offset = (colnr_T)(s - newline);
+
+ // this may free "newline"
ml_replace(curwin->w_cursor.lnum, newline, false);
if (!(flags & SIN_NOMARK)) {
extmark_splice_cols(curbuf,
(int)curwin->w_cursor.lnum-1,
skipcols,
- (int)(p-oldline) - skipcols,
- (int)(s-newline) - skipcols,
+ old_offset - skipcols,
+ new_offset - skipcols,
kExtmarkUndo);
}
@@ -311,15 +315,14 @@ int set_indent(int size, int flags)
// Correct saved cursor position if it is in this line.
if (saved_cursor.lnum == curwin->w_cursor.lnum) {
- if (saved_cursor.col >= (colnr_T)(p - oldline)) {
+ if (saved_cursor.col >= old_offset) {
// Cursor was after the indent, adjust for the number of
// bytes added/removed.
- saved_cursor.col += ind_len - (colnr_T)(p - oldline);
-
- } else if (saved_cursor.col >= (colnr_T)(s - newline)) {
+ saved_cursor.col += ind_len - old_offset;
+ } else if (saved_cursor.col >= new_offset) {
// Cursor was in the indent, and is now after it, put it back
// at the start of the indent (replacing spaces with TAB).
- saved_cursor.col = (colnr_T)(s - newline);
+ saved_cursor.col = new_offset;
}
}
retval = true;