diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-11-10 19:19:36 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-11-10 19:19:36 +0100 |
commit | ddd1f9183bed00d096f29c503721ac559174a29f (patch) | |
tree | 0ad97968954e7ff342475ebac38896b1694dba62 /src/ex_cmds.c | |
parent | ded5f1bed7ff2d138b3ee0f9610d17290b62692d (diff) | |
download | vim-git-ddd1f9183bed00d096f29c503721ac559174a29f.tar.gz |
patch 8.1.0516: :move command marks buffer modified when nothing changedv8.1.0516
Problem: :move command marks buffer modified when nothing changed.
Solution: Do not set 'modified'. Add a test. (Jason Franklin)
Diffstat (limited to 'src/ex_cmds.c')
-rw-r--r-- | src/ex_cmds.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 7512785c9..cb728d405 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -899,9 +899,9 @@ do_move(linenr_T line1, linenr_T line2, linenr_T dest) { char_u *str; linenr_T l; - linenr_T extra; /* Num lines added before line1 */ - linenr_T num_lines; /* Num lines moved */ - linenr_T last_line; /* Last line in file after adding new text */ + linenr_T extra; // Num lines added before line1 + linenr_T num_lines; // Num lines moved + linenr_T last_line; // Last line in file after adding new text #ifdef FEAT_FOLDING win_T *win; tabpage_T *tp; @@ -909,10 +909,24 @@ do_move(linenr_T line1, linenr_T line2, linenr_T dest) if (dest >= line1 && dest < line2) { - EMSG(_("E134: Move lines into themselves")); + EMSG(_("E134: Cannot move a range of lines into itself")); return FAIL; } + // Do nothing if we are not actually moving any lines. This will prevent + // the 'modified' flag from being set without cause. + if (dest == line1 - 1 || dest == line2) + { + // Move the cursor as if lines were moved (see below) to be backwards + // compatible. + if (dest >= line1) + curwin->w_cursor.lnum = dest; + else + curwin->w_cursor.lnum = dest + (line2 - line1) + 1; + + return OK; + } + num_lines = line2 - line1 + 1; /* |