mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.1.0516: :move command marks buffer modified when nothing changed
Problem: :move command marks buffer modified when nothing changed. Solution: Do not set 'modified'. Add a test. (Jason Franklin)
This commit is contained in:
parent
ded5f1bed7
commit
ddd1f9183b
@ -123,6 +123,7 @@ NEW_TESTS = \
|
|||||||
test_mksession \
|
test_mksession \
|
||||||
test_mksession_utf8 \
|
test_mksession_utf8 \
|
||||||
test_modeline \
|
test_modeline \
|
||||||
|
test_move \
|
||||||
test_nested_function \
|
test_nested_function \
|
||||||
test_netbeans \
|
test_netbeans \
|
||||||
test_normal \
|
test_normal \
|
||||||
|
@ -899,9 +899,9 @@ do_move(linenr_T line1, linenr_T line2, linenr_T dest)
|
|||||||
{
|
{
|
||||||
char_u *str;
|
char_u *str;
|
||||||
linenr_T l;
|
linenr_T l;
|
||||||
linenr_T extra; /* Num lines added before line1 */
|
linenr_T extra; // Num lines added before line1
|
||||||
linenr_T num_lines; /* Num lines moved */
|
linenr_T num_lines; // Num lines moved
|
||||||
linenr_T last_line; /* Last line in file after adding new text */
|
linenr_T last_line; // Last line in file after adding new text
|
||||||
#ifdef FEAT_FOLDING
|
#ifdef FEAT_FOLDING
|
||||||
win_T *win;
|
win_T *win;
|
||||||
tabpage_T *tp;
|
tabpage_T *tp;
|
||||||
@ -909,10 +909,24 @@ do_move(linenr_T line1, linenr_T line2, linenr_T dest)
|
|||||||
|
|
||||||
if (dest >= line1 && dest < line2)
|
if (dest >= line1 && dest < line2)
|
||||||
{
|
{
|
||||||
EMSG(_("E134: Move lines into themselves"));
|
EMSG(_("E134: Cannot move a range of lines into itself"));
|
||||||
return FAIL;
|
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;
|
num_lines = line2 - line1 + 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -41,6 +41,7 @@ source test_match.vim
|
|||||||
source test_menu.vim
|
source test_menu.vim
|
||||||
source test_messages.vim
|
source test_messages.vim
|
||||||
source test_modeline.vim
|
source test_modeline.vim
|
||||||
|
source test_move.vim
|
||||||
source test_partial.vim
|
source test_partial.vim
|
||||||
source test_popup.vim
|
source test_popup.vim
|
||||||
source test_put.vim
|
source test_put.vim
|
||||||
|
40
src/testdir/test_move.vim
Normal file
40
src/testdir/test_move.vim
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
" Test the ":move" command.
|
||||||
|
|
||||||
|
func Test_move()
|
||||||
|
enew!
|
||||||
|
call append(0, ['line 1', 'line 2', 'line 3'])
|
||||||
|
g /^$/ delete _
|
||||||
|
set nomodified
|
||||||
|
|
||||||
|
move .
|
||||||
|
call assert_equal(['line 1', 'line 2', 'line 3'], getline(1, 3))
|
||||||
|
call assert_false(&modified)
|
||||||
|
|
||||||
|
1,2move 0
|
||||||
|
call assert_equal(['line 1', 'line 2', 'line 3'], getline(1, 3))
|
||||||
|
call assert_false(&modified)
|
||||||
|
|
||||||
|
1,3move 3
|
||||||
|
call assert_equal(['line 1', 'line 2', 'line 3'], getline(1, 3))
|
||||||
|
call assert_false(&modified)
|
||||||
|
|
||||||
|
1move 2
|
||||||
|
call assert_equal(['line 2', 'line 1', 'line 3'], getline(1, 3))
|
||||||
|
call assert_true(&modified)
|
||||||
|
set nomodified
|
||||||
|
|
||||||
|
3move 0
|
||||||
|
call assert_equal(['line 3', 'line 2', 'line 1'], getline(1, 3))
|
||||||
|
call assert_true(&modified)
|
||||||
|
set nomodified
|
||||||
|
|
||||||
|
2,3move 0
|
||||||
|
call assert_equal(['line 2', 'line 1', 'line 3'], getline(1, 3))
|
||||||
|
call assert_true(&modified)
|
||||||
|
set nomodified
|
||||||
|
|
||||||
|
call assert_fails('1,2move 1', 'E134')
|
||||||
|
call assert_fails('2,3move 2', 'E134')
|
||||||
|
|
||||||
|
%bwipeout!
|
||||||
|
endfunc
|
@ -792,6 +792,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
516,
|
||||||
/**/
|
/**/
|
||||||
515,
|
515,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user