fold: foldMoveRange(): fix :move bug #6534

Closes #6540

In #6221 there was a mistake in calculating which folds need to be
re-ordered. When there are no folds after those that have been adjusted,
then `move_end` remains 0. This results in reverse_fold_order()
swapping folds that have been adjusted with uninitialised folds in the
remainder of the grow array.

Add a check in foldMoveRange() to account for this case.
This commit is contained in:
Matthew Malcomson
2017-04-16 20:15:50 +01:00
committed by Justin M. Keyes
parent 77a4f8f235
commit 263849b2dd
2 changed files with 26 additions and 4 deletions

View File

@@ -2765,10 +2765,13 @@ void foldMoveRange(garray_T *gap, const linenr_T line1, const linenr_T line2,
} }
dest_index = FOLD_INDEX(fp, gap); dest_index = FOLD_INDEX(fp, gap);
// All folds are now correct, but they are not necessarily in the correct // All folds are now correct, but not necessarily in the correct order.
// order. // We must swap folds in the range [move_end, dest_index) with those in the
// We have to swap folds in the range [move_end, dest_index) with those in // range [move_start, move_end).
// the range [move_start, move_end). if (move_end == 0) {
// There are no folds after those moved, so none were moved out of order.
return;
}
reverse_fold_order(gap, move_start, dest_index - 1); reverse_fold_order(gap, move_start, dest_index - 1);
reverse_fold_order(gap, move_start, move_start + dest_index - move_end - 1); reverse_fold_order(gap, move_start, move_start + dest_index - move_end - 1);
reverse_fold_order(gap, move_start + dest_index - move_end, dest_index - 1); reverse_fold_order(gap, move_start + dest_index - move_end, dest_index - 1);

View File

@@ -232,6 +232,25 @@ a
a]], '2,3m0') a]], '2,3m0')
eq({1, 2, 0, 0, 0}, get_folds()) eq({1, 2, 0, 0, 0}, get_folds())
end) end)
it('handles shifting all remaining folds', function()
test_move_indent([[
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a]], '13m7')
eq({1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 0}, get_folds())
end)
end) end)
it('updates correctly on :read', function() it('updates correctly on :read', function()
-- luacheck: ignore 621 -- luacheck: ignore 621