Mercurial > vim
diff src/ex_cmds.c @ 14206:f2ab259ef88a v8.1.0120
patch 8.1.0120: buffer 'modified' set even when :sort has no changes
commit https://github.com/vim/vim/commit/dc9e955fb07f410d5d3e981ce18d895dd2847c85
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jun 28 11:28:08 2018 +0200
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)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 28 Jun 2018 11:30:07 +0200 |
parents | 6fbb8dfb3389 |
children | 539b070778b0 |
line wrap: on
line diff
--- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -398,6 +398,7 @@ ex_sort(exarg_T *eap) colnr_T end_col; int sort_what = 0; int format_found = 0; + int change_occurred = FALSE; // Buffer contents changed. /* Sorting one line is really quick! */ if (count <= 1) @@ -616,12 +617,19 @@ ex_sort(exarg_T *eap) lnum = eap->line2; for (i = 0; i < count; ++i) { - s = ml_get(nrs[eap->forceit ? count - i - 1 : i].lnum); + 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 - * ml_append(). And it's needed for "unique". */ + // Copy the line into a buffer, it may become invalid in + // ml_append(). And it's needed for "unique". STRCPY(sortbuf1, s); if (ml_append(lnum++, sortbuf1, (colnr_T)0, FALSE) == FAIL) break; @@ -644,7 +652,9 @@ ex_sort(exarg_T *eap) mark_adjust(eap->line2 - deleted, eap->line2, (long)MAXLNUM, -deleted); else if (deleted < 0) mark_adjust(eap->line2, MAXLNUM, -deleted, 0L); - changed_lines(eap->line1, 0, eap->line2 + 1, -deleted); + + if (change_occurred || deleted != 0) + changed_lines(eap->line1, 0, eap->line2 + 1, -deleted); curwin->w_cursor.lnum = eap->line1; beginline(BL_WHITE | BL_FIX);