aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/ex_cmds.c22
-rw-r--r--src/nvim/fold.c6
-rw-r--r--src/nvim/testdir/Makefile2
-rw-r--r--src/nvim/testdir/test45.in80
-rw-r--r--src/nvim/testdir/test45.ok18
-rw-r--r--src/nvim/version.c2
-rw-r--r--test/functional/legacy/045_folding_spec.lua139
7 files changed, 162 insertions, 107 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index a517037431..4d62dd0ff9 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -690,9 +690,17 @@ int 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
+
+ // Moving lines seems to corrupt the folds, delete folding info now
+ // and recreate it when finished. Don't do this for manual folding, it
+ // would delete all folds.
+ bool isFolded = hasAnyFolding(curwin) && !foldmethodIsManual(curwin);
+ if (isFolded) {
+ deleteFoldRecurse(&curwin->w_folds);
+ }
if (dest >= line1 && dest < line2) {
EMSG(_("E134: Move lines into themselves"));
@@ -777,8 +785,14 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
if (dest > last_line + 1)
dest = last_line + 1;
changed_lines(line1, 0, dest, 0L);
- } else
+ } else {
changed_lines(dest + 1, 0, line1 + num_lines, 0L);
+ }
+
+ // recreate folds
+ if (isFolded) {
+ foldUpdateAll(curwin);
+ }
return OK;
}
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index 2e32e78062..6c135ef47b 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -767,9 +767,9 @@ void foldUpdate(win_T *wp, linenr_T top, linenr_T bot)
return;
}
- /* Mark all folds from top to bot as maybe-small. */
- (void)foldFind(&curwin->w_folds, top, &fp);
- while (fp < (fold_T *)curwin->w_folds.ga_data + curwin->w_folds.ga_len
+ // Mark all folds from top to bot as maybe-small.
+ (void)foldFind(&wp->w_folds, top, &fp);
+ while (fp < (fold_T *)wp->w_folds.ga_data + wp->w_folds.ga_len
&& fp->fd_top < bot) {
fp->fd_small = MAYBE;
++fp;
diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile
index fe511166f2..d1a7abfbf7 100644
--- a/src/nvim/testdir/Makefile
+++ b/src/nvim/testdir/Makefile
@@ -15,7 +15,7 @@ SCRIPTS := \
test30.out \
test32.out test34.out \
test36.out test37.out test40.out \
- test42.out test45.out \
+ test42.out \
test47.out test48.out test49.out \
test52.out test53.out test55.out \
test64.out \
diff --git a/src/nvim/testdir/test45.in b/src/nvim/testdir/test45.in
deleted file mode 100644
index e5af5073d9..0000000000
--- a/src/nvim/testdir/test45.in
+++ /dev/null
@@ -1,80 +0,0 @@
-Tests for folding. vim: set ft=vim :
-
-STARTTEST
-:so small.vim
-:" We also need the +syntax feature here.
-:if !has("syntax")
- e! test.ok
- w! test.out
- qa!
-:endif
-:" basic test if a fold can be created, opened, moving to the end and closed
-/^1
-zf2j:call append("$", "manual " . getline(foldclosed(".")))
-zo:call append("$", foldclosed("."))
-]z:call append("$", getline("."))
-zc:call append("$", getline(foldclosed(".")))
-:" test folding with markers.
-:set fdm=marker fdl=1 fdc=3
-/^5
-:call append("$", "marker " . foldlevel("."))
-[z:call append("$", foldlevel("."))
-jo{{ r{jj:call append("$", foldlevel("."))
-kYpj:call append("$", foldlevel("."))
-:" test folding with indent
-:set fdm=indent sw=2
-/^2 b
-i jI :call append("$", "indent " . foldlevel("."))
-k:call append("$", foldlevel("."))
-:" test syntax folding
-:set fdm=syntax fdl=0
-:syn region Hup start="dd" end="ii" fold contains=Fd1,Fd2,Fd3
-:syn region Fd1 start="ee" end="ff" fold contained
-:syn region Fd2 start="gg" end="hh" fold contained
-:syn region Fd3 start="commentstart" end="commentend" fold contained
-Gzk:call append("$", "folding " . getline("."))
-k:call append("$", getline("."))
-jAcommentstart Acommentend:set fdl=1
-3j:call append("$", getline("."))
-:set fdl=0
-zO j:call append("$", getline("."))
-:" test expression folding
-:fun Flvl()
- let l = getline(v:lnum)
- if l =~ "bb$"
- return 2
- elseif l =~ "gg$"
- return "s1"
- elseif l =~ "ii$"
- return ">2"
- elseif l =~ "kk$"
- return "0"
- endif
- return "="
-endfun
-:set fdm=expr fde=Flvl()
-/bb$
-:call append("$", "expr " . foldlevel("."))
-/hh$
-:call append("$", foldlevel("."))
-/ii$
-:call append("$", foldlevel("."))
-/kk$
-:call append("$", foldlevel("."))
-:/^last/+1,$w! test.out
-:delfun Flvl
-:qa!
-ENDTEST
-
-1 aa
-2 bb
-3 cc
-4 dd {{{
-5 ee {{{ }}}
-6 ff }}}
-7 gg
-8 hh
-9 ii
-a jj
-b kk
-last
diff --git a/src/nvim/testdir/test45.ok b/src/nvim/testdir/test45.ok
deleted file mode 100644
index f04996e337..0000000000
--- a/src/nvim/testdir/test45.ok
+++ /dev/null
@@ -1,18 +0,0 @@
-manual 1 aa
--1
-3 cc
-1 aa
-marker 2
-1
-1
-0
-indent 2
-1
-folding 9 ii
- 3 cc
-7 gg
-8 hh
-expr 2
-1
-2
-0
diff --git a/src/nvim/version.c b/src/nvim/version.c
index d8cd0182a8..026eab46d0 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -588,7 +588,7 @@ static int included_patches[] = {
// 703 NA
702,
// 701 NA
- // 700,
+ 700,
699,
698,
697,
diff --git a/test/functional/legacy/045_folding_spec.lua b/test/functional/legacy/045_folding_spec.lua
new file mode 100644
index 0000000000..04b623ff3b
--- /dev/null
+++ b/test/functional/legacy/045_folding_spec.lua
@@ -0,0 +1,139 @@
+-- Tests for folding.
+
+local helpers = require('test.functional.helpers')
+local feed, insert, clear, execute, expect =
+ helpers.feed, helpers.insert, helpers.clear, helpers.execute, helpers.expect
+
+describe('folding', function()
+ before_each(clear)
+
+ it('is working', function()
+ insert([[
+ 1 aa
+ 2 bb
+ 3 cc
+ 4 dd {{{
+ 5 ee {{{ }}}
+ 6 ff }}}
+ 7 gg
+ 8 hh
+ 9 ii
+ a jj
+ b kk
+ last]])
+
+ -- Basic test if a fold can be created, opened, moving to the end and
+ -- closed.
+ execute('/^1')
+ feed('zf2j')
+ execute('call append("$", "manual " . getline(foldclosed(".")))')
+ feed('zo')
+ execute('call append("$", foldclosed("."))')
+ feed(']z')
+ execute('call append("$", getline("."))')
+ feed('zc')
+ execute('call append("$", getline(foldclosed(".")))')
+ -- Test folding with markers.
+ execute('set fdm=marker fdl=1 fdc=3')
+ execute('/^5')
+ execute('call append("$", "marker " . foldlevel("."))')
+ feed('[z')
+ execute('call append("$", foldlevel("."))')
+ feed('jo{{ <esc>r{jj')
+ execute('call append("$", foldlevel("."))')
+ feed('kYpj')
+ execute('call append("$", foldlevel("."))')
+ -- Test folding with indent.
+ execute('set fdm=indent sw=2')
+ execute('/^2 b')
+ feed('i <esc>jI <esc>')
+ execute('call append("$", "indent " . foldlevel("."))')
+ feed('k')
+ execute('call append("$", foldlevel("."))')
+ -- Test syntax folding.
+ execute('set fdm=syntax fdl=0')
+ execute('syn region Hup start="dd" end="ii" fold contains=Fd1,Fd2,Fd3')
+ execute('syn region Fd1 start="ee" end="ff" fold contained')
+ execute('syn region Fd2 start="gg" end="hh" fold contained')
+ execute('syn region Fd3 start="commentstart" end="commentend" fold contained')
+ feed('Gzk')
+ execute('call append("$", "folding " . getline("."))')
+ feed('k')
+ execute('call append("$", getline("."))')
+ feed('jAcommentstart <esc>Acommentend<esc>')
+ execute('set fdl=1')
+ feed('3j')
+ execute('call append("$", getline("."))')
+ execute('set fdl=0')
+ feed('zO<C-L>j')
+ execute('call append("$", getline("."))')
+ -- Test expression folding.
+ execute('fun Flvl()')
+ execute(' let l = getline(v:lnum)')
+ execute(' if l =~ "bb$"')
+ execute(' return 2')
+ execute(' elseif l =~ "gg$"')
+ execute(' return "s1"')
+ execute(' elseif l =~ "ii$"')
+ execute(' return ">2"')
+ execute(' elseif l =~ "kk$"')
+ execute(' return "0"')
+ execute(' endif')
+ execute(' return "="')
+ execute('endfun')
+ execute('set fdm=expr fde=Flvl()')
+ execute('/bb$')
+ execute('call append("$", "expr " . foldlevel("."))')
+ execute('/hh$')
+ execute('call append("$", foldlevel("."))')
+ execute('/ii$')
+ execute('call append("$", foldlevel("."))')
+ execute('/kk$')
+ execute('call append("$", foldlevel("."))')
+ execute('0,/^last/delete')
+ execute('delfun Flvl')
+
+ -- Assert buffer contents.
+ expect([[
+ manual 1 aa
+ -1
+ 3 cc
+ 1 aa
+ marker 2
+ 1
+ 1
+ 0
+ indent 2
+ 1
+ folding 9 ii
+ 3 cc
+ 7 gg
+ 8 hh
+ expr 2
+ 1
+ 2
+ 0]])
+ end)
+
+ it('can open after :move', function()
+ insert([[
+ Test fdm=indent and :move bug END
+ line2
+ Test fdm=indent START
+ line3
+ line4]])
+
+ execute('set noai nosta')
+ execute('set fdm=indent')
+ execute('1m1')
+ feed('2jzc')
+ execute('m0')
+
+ expect([[
+ Test fdm=indent START
+ line3
+ line4
+ Test fdm=indent and :move bug END
+ line2]])
+ end)
+end)