diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-09-27 10:47:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-27 10:47:37 +0200 |
commit | 33887206b9e94a1ed7cce898d869023ff6ceb874 (patch) | |
tree | e4b499748288526e5a41e5880d60184bea324784 /src/nvim/ex_cmds.c | |
parent | ba17bcfefc626729d30388401b77ef524f9c90d2 (diff) | |
parent | 96a34daab76f4ab24fea499d5fd929542c0997b0 (diff) | |
download | rneovim-33887206b9e94a1ed7cce898d869023ff6ceb874.tar.gz rneovim-33887206b9e94a1ed7cce898d869023ff6ceb874.tar.bz2 rneovim-33887206b9e94a1ed7cce898d869023ff6ceb874.zip |
Merge #9060 from janlazo/vim-8.1.0120
Diffstat (limited to 'src/nvim/ex_cmds.c')
-rw-r--r-- | src/nvim/ex_cmds.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index aaa4dbdfb7..6f94dedd76 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)) { @@ -584,8 +585,16 @@ 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); + for (i = 0; i < count; i++) { + 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); |