aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_cmds.c
diff options
context:
space:
mode:
authorJan Edmund Lazo <janedmundlazo@hotmail.com>2018-09-26 21:21:14 -0400
committerJan Edmund Lazo <janedmundlazo@hotmail.com>2018-09-26 21:32:45 -0400
commit25e6d37705a9152deaa74455b2cc18b3f71f6137 (patch)
treee809e864263afece339be5104b244bfc2079b3f6 /src/nvim/ex_cmds.c
parentfc18fad74ff3be9929d9d10de964f4813497fba0 (diff)
downloadrneovim-25e6d37705a9152deaa74455b2cc18b3f71f6137.tar.gz
rneovim-25e6d37705a9152deaa74455b2cc18b3f71f6137.tar.bz2
rneovim-25e6d37705a9152deaa74455b2cc18b3f71f6137.zip
vim-patch:8.1.0120: buffer 'modified' set even when :sort has no changes
Problem: Buffer 'modified' set even when :sort has no changes. Solution: Only set 'modified' when lines are moved. (Jason Franklin) https://github.com/vim/vim/commit/dc9e955fb07f410d5d3e981ce18d895dd2847c85
Diffstat (limited to 'src/nvim/ex_cmds.c')
-rw-r--r--src/nvim/ex_cmds.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index aaa4dbdfb7..892458dab7 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -424,6 +424,7 @@ void ex_sort(exarg_T *eap)
sort_abort = sort_ic = sort_rx = sort_nr = sort_flt = 0;
size_t format_found = 0;
+ bool change_occurred = false; // Buffer contents changed.
for (p = eap->arg; *p != NUL; ++p) {
if (ascii_iswhite(*p)) {
@@ -585,7 +586,15 @@ void ex_sort(exarg_T *eap)
// Insert the lines in the sorted order below the last one.
lnum = eap->line2;
for (i = 0; i < count; ++i) {
- s = ml_get(nrs[eap->forceit ? count - i - 1 : i].lnum);
+ const linenr_T get_lnum = nrs[eap->forceit ? count - i - 1 : i].lnum;
+
+ // If the original line number of the line being placed is not the same
+ // as "lnum" (accounting for offset), we know that the buffer changed.
+ if (get_lnum + ((linenr_T)count - 1) != lnum) {
+ change_occurred = true;
+ }
+
+ s = ml_get(get_lnum);
if (!unique || i == 0
|| (sort_ic ? STRICMP(s, sortbuf1) : STRCMP(s, sortbuf1)) != 0) {
// Copy the line into a buffer, it may become invalid in
@@ -617,7 +626,9 @@ void ex_sort(exarg_T *eap)
} else if (deleted < 0) {
mark_adjust(eap->line2, MAXLNUM, -deleted, 0L, false);
}
- changed_lines(eap->line1, 0, eap->line2 + 1, -deleted, true);
+ if (change_occurred || deleted != 0) {
+ changed_lines(eap->line1, 0, eap->line2 + 1, -deleted, true);
+ }
curwin->w_cursor.lnum = eap->line1;
beginline(BL_WHITE | BL_FIX);