Skip to content

Commit

Permalink
nudge after label-mode #181
Browse files Browse the repository at this point in the history
Instead of immediately nudging after finding first result, wait until
label-mode has finished, so exclusive (t-like) mode also works
correctly icm with label-mode. 

- fixes #176
- also loosens the criterion for nudging, fixes #179
  • Loading branch information
HarmtH authored Aug 30, 2020
1 parent afe9454 commit 7d82982
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
12 changes: 8 additions & 4 deletions plugin/sneak.vim
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ func! sneak#to(op, input, inputlen, count, register, repeatmotion, reverse, incl
endif
endfor

if nudge && (!is_v || max(matchpos) > 0)
call sneak#util#nudge(a:reverse) "undo nudge for t
endif

if 0 == max(matchpos)
if nudge
call sneak#util#nudge(a:reverse) "undo nudge for t
endif

let km = empty(&keymap) ? '' : ' ('.&keymap.' keymap)'
call sneak#util#echo('not found'.(max(bounds) ? printf(km.' (in columns %d-%d): %s', bounds[0], bounds[1], a:input) : km.': '.a:input))
return
Expand Down Expand Up @@ -228,6 +228,10 @@ func! sneak#to(op, input, inputlen, count, register, repeatmotion, reverse, incl
let target = (2 == a:label || !empty(label) || (a:label && g:sneak#opt.label && (is_op || s.hasmatches(1)))) && !max(bounds)
\ ? sneak#label#to(s, is_v, label) : ""

if nudge
call sneak#util#nudge(a:reverse) "undo nudge for t
endif

if is_op && 2 != a:inclusive && !a:reverse
" f/t operations do not apply to the current character; nudge the cursor.
call sneak#util#nudge(1)
Expand Down
41 changes: 41 additions & 0 deletions tests/test.vader
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,47 @@ Expect:
ab7cdef ab8cdef ab9cdef ab0cdef ab1cdef ab2cdef
ab1cdef ab2cdef ab3cdef ab4cdef ab5cdef ab6cdef

###########################################################
# test streak mode with exclusive sneak

Execute (mappings for exclusive streak mode):
nnoremap <silent> t :<c-u>call sneak#wrap('', 1, 0, 0, 2)<cr>
nnoremap <silent> T :<c-u>call sneak#wrap('', 1, 1, 0, 2)<cr>
onoremap <silent> t :<c-u>call sneak#wrap(v:operator, 1, 0, 0, 2)<cr>
onoremap <silent> T :<c-u>call sneak#wrap(v:operator, 1, 1, 0, 2)<cr>

Do (sneak-streak to correct character with exclusive sneak, forwards, normal [issue #176]):
tcax

Expect:
ab1cdef ab2cdef abcdef ab4cdef ab5cdef ab6cdef
ab7cdef ab8cdef ab9cdef ab0cdef ab1cdef ab2cdef
ab1cdef ab2cdef ab3cdef ab4cdef ab5cdef ab6cdef

Do (sneak-streak to correct character with exclusive sneak, backwards, normal [issue #176]):
$Tcsx

Expect:
ab1cdef ab2cdef ab3cef ab4cdef ab5cdef ab6cdef
ab7cdef ab8cdef ab9cdef ab0cdef ab1cdef ab2cdef
ab1cdef ab2cdef ab3cdef ab4cdef ab5cdef ab6cdef

Do (sneak-streak to correct character with exclusive sneak, forwards, op-pending [issue #176]):
wwdtfa

Expect:
ab1cdef ab2cdef f ab6cdef
ab7cdef ab8cdef ab9cdef ab0cdef ab1cdef ab2cdef
ab1cdef ab2cdef ab3cdef ab4cdef ab5cdef ab6cdef

Do (sneak-streak to correct character with exclusive sneak, backwards, op-pending [issue #176]):
5wcTb;X

Expect:
ab1cdef ab2cdef ab3cdef abXab6cdef
ab7cdef ab8cdef ab9cdef ab0cdef ab1cdef ab2cdef
ab1cdef ab2cdef ab3cdef ab4cdef ab5cdef ab6cdef

Execute (cleanup):
silent! unmap f
silent! unmap F
Expand Down

0 comments on commit 7d82982

Please sign in to comment.