diff options
-rw-r--r-- | src/nvim/fold.c | 11 | ||||
-rw-r--r-- | test/functional/normal/fold_spec.lua | 19 |
2 files changed, 26 insertions, 4 deletions
diff --git a/src/nvim/fold.c b/src/nvim/fold.c index d810aee0ce..34db4d2171 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -2765,10 +2765,13 @@ void foldMoveRange(garray_T *gap, const linenr_T line1, const linenr_T line2, } dest_index = FOLD_INDEX(fp, gap); - // All folds are now correct, but they are not necessarily in the correct - // order. - // We have to swap folds in the range [move_end, dest_index) with those in - // the range [move_start, move_end). + // All folds are now correct, but not necessarily in the correct order. + // We must swap folds in the range [move_end, dest_index) with those in 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, move_start + dest_index - move_end - 1); reverse_fold_order(gap, move_start + dest_index - move_end, dest_index - 1); diff --git a/test/functional/normal/fold_spec.lua b/test/functional/normal/fold_spec.lua index 85e4631b61..00e83bedc8 100644 --- a/test/functional/normal/fold_spec.lua +++ b/test/functional/normal/fold_spec.lua @@ -232,6 +232,25 @@ a a]], '2,3m0') eq({1, 2, 0, 0, 0}, get_folds()) 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) it('updates correctly on :read', function() -- luacheck: ignore 621 |