Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce search behavior according to &foldopen #152

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion plugin/sneak.vim
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,19 @@ func! sneak#to(op, input, inputlen, count, repeatmotion, reverse, inclusive, str
let nudge = sneak#util#nudge(!a:reverse) "special case for t
endif

" detect whether folds should be opened during search according to &foldopen
let l:search_foldopen = !empty(matchstr(&foldopen,"search"))

for i in range(1, max([1, skip])) "jump to the [count]th match
" if in a closed fold, jump to end of it for 'set foldopen-=search'
let l:winview = winsaveview()
if !l:search_foldopen && foldclosed('.') > -1
call cursor(a:reverse ? foldclosed('.') : foldclosedend('.'),
\ a:reverse ? 1 : col('$'))
endif
let matchpos = s.dosearch()
if 0 == max(matchpos)
if 0 == max(matchpos) " if no search results found
call winrestview(l:winview) " revert jump to end of fold and break
break
else
let nudge = !a:inclusive
Expand All @@ -172,6 +182,11 @@ func! sneak#to(op, input, inputlen, count, repeatmotion, reverse, inclusive, str
endif
"search succeeded

" open folds when jumping to matches if necessary
if l:search_foldopen
norm! zv
endif

call sneak#hl#removehl()

if (!is_op || a:op ==# 'y') "position _after_ search
Expand Down
86 changes: 85 additions & 1 deletion tests/test.vader
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# BUG: highlight targets are bogus if &iminsert=1
# BUG: sneak cannot find ёе: in this text
# BUG: sneak cannot find е:а in this text
#
#
# ёе:а
# ёе:а
# ёе:а
Expand Down Expand Up @@ -1107,3 +1107,87 @@ Execute (cleanup):
nmap S <Plug>Sneak_S
call sneak#init()

###########################################################
# Fold Handling

Given:
aaaaaaaaaa
aaaaabaaba
ababaaaaaa
aaaaaabaaa

Do (s and ; in folds):
jzfjggsba;x

Expect:
aaaaaaaaaa
aaaaabaaa
ababaaaaaa
aaaaaabaaa

Do (s and \ in folds):
jzfjGsba\\x

Expect:
aaaaaaaaaa
aaaaabaaba
aabaaaaaa
aaaaaabaaa

Do (S and ; in folds):
jzfjG$Sba;x

Expect:
aaaaaaaaaa
aaaaabaaba
abaaaaaaa
aaaaaabaaa

Do (S and \ in folds):
jzfjggSba\\x

Expect:
aaaaaaaaaa
aaaaabaaa
ababaaaaaa
aaaaaabaaa

Execute (set foldopen-=search):
set foldopen-=search

Do (s and ; in folds):
jzfjggsba;x

Expect:
aaaaaaaaaa
aaaaabaaba
ababaaaaaa
aaaaaaaaa

Do (s and \ in folds):
jzfjGsba\\x

Expect:
aaaaaaaaaa
aaaaaabaaa

Do (S and ; in folds):
jzfjG$Sba;zvx

Expect:
aaaaaaaaaa
aaaaabaaba
abaaaaaaa
aaaaaabaaa

Do (S and \ in folds):
jzfjggSba\\x

Expect:
aaaaaaaaaa
aaaaabaaba
ababaaaaaa
aaaaaaaaa

Execute (cleanup):
set foldopen+=search