Skip to content

Commit

Permalink
Fix behavior when moving into folds. Fixes #67.
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoren committed Jul 4, 2022
1 parent 1f7eaf5 commit 4bec560
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions autoload/wordmotion.vim
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ function wordmotion#motion(count, mode, flags, uppercase, extra)
endif
endif

if (a:mode == 'n' || a:mode == 'x') && &g:foldopen =~# '\%(^\|,\)hor\%(,\|$\)'
normal! zv
endif

let &cpoptions = l:cpo
endfunction

Expand Down
44 changes: 44 additions & 0 deletions tests/fold.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Given (a fold):
before fold
start fold
inside fold
end fold
after fold

Before (save fold options and create fold):
Save &foldenable, &foldlevel, &foldmethod, &foldopen
set foldenable
set foldlevel=0
set foldmethod=manual
set foldopen+=hor
2,4fold

After (delete fold and restore fold options):
3normal zd
Restore &foldenable, &foldlevel, &foldmethod, &foldopen

Execute (move forward into fold):
normal 2w
AssertEqual [2, 1], getcurpos()[1:2]
AssertEqual -1, foldclosed(2)
AssertEqual -1, foldclosedend(2)

Execute (move backward into fold):
normal Gb
AssertEqual [4, 5], getcurpos()[1:2]
AssertEqual -1, foldclosed(4)
AssertEqual -1, foldclosedend(4)

Execute (move into fold in visual mode):
normal v2w
AssertEqual [2, 1], getcurpos()[1:2]
AssertEqual -1, foldclosed(2)
AssertEqual -1, foldclosedend(2)
AssertEqual 'v', mode(1)

Execute (move into fold without hor in foldopen):
set foldopen-=hor
normal 2w
AssertEqual [2, 1], getcurpos()[1:2]
AssertEqual 2, foldclosed(2)
AssertEqual 4, foldclosedend(2)

0 comments on commit 4bec560

Please sign in to comment.