Skip to content

Commit

Permalink
fix #74: exclusive (t) in visual-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmk committed Mar 13, 2014
1 parent d673c11 commit 0e5436b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
12 changes: 7 additions & 5 deletions autoload/sneak/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ func! sneak#util#skipfold(current_line, reverse)
return 0
endf

"Moves the cursor 1 char to the left or right; wraps at EOL.
"Moves the cursor 1 char to the left or right; wraps at EOL, but _not_ EOF.
func! sneak#util#nudge(right)
let ww_orig = &whichwrap
set whichwrap+=h,l
exec 'norm! ' a:right ? 'l' : 'h'
let &whichwrap = ww_orig
let nextchar = searchpos('\_.', 'nW'.(a:right ? '' : 'b'))
if [0, 0] == nextchar
return 0
endif
call cursor(nextchar)
return 1
endf

20 changes: 10 additions & 10 deletions plugin/sneak.vim
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func! sneak#to(op, input, inputlen, count, repeatmotion, reverse, inclusive, str
redraw | echo '' | return
endif

let is_op = !empty(a:op) && !sneak#util#isvisualop(a:op) "operator-pending invocation
let is_v = sneak#util#isvisualop(a:op)
let is_op = !empty(a:op) && !is_v "operator-pending invocation
let s = g:sneak#search#instance
call s.init(a:input, a:repeatmotion, a:reverse)

Expand Down Expand Up @@ -120,14 +121,14 @@ func! sneak#to(op, input, inputlen, count, repeatmotion, reverse, inclusive, str
call s:ft_hook()
endif

if is_op && !sneak#util#isvisualop(a:op) && 2 != a:inclusive
if is_op && 2 != a:inclusive
norm! v
endif

let nextchar = searchpos('\_.', 'n'.(s.search_options_no_s))
let nudge = !a:inclusive && a:repeatmotion && nextchar == s.dosearch('n')
if nudge
call sneak#util#nudge(!a:reverse) "special case for t
let nudge = sneak#util#nudge(!a:reverse) "special case for t
endif

for i in range(1, max([1, skip])) "jump to the [count]th match
Expand All @@ -139,15 +140,15 @@ func! sneak#to(op, input, inputlen, count, repeatmotion, reverse, inclusive, str
endif
endfor

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

if sneak#util#isvisualop(a:op) "user was in visual mode, extend the selection.
if is_v "user was in visual mode, extend the selection.
norm! gv
if max(matchpos) > 0 | call cursor(matchpos) | endif
endif

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

if 0 == max(matchpos)
let km = empty(&keymap) ? '' : ' ('.&keymap.' keymap)'
call sneak#util#echo('not found'.((max(l:bounds) > 0) ? printf(km.' (in columns %d-%d): %s', l:bounds[0], l:bounds[1], a:input) : km.': '.a:input))
Expand Down Expand Up @@ -183,10 +184,9 @@ func! sneak#to(op, input, inputlen, count, repeatmotion, reverse, inclusive, str

"enter streak-mode iff there are >=2 _additional_ on-screen matches.
let target = (2 == a:streak || (a:streak && g:sneak#opt.streak)) && 0 == max(l:bounds) && s.hasmatches(2)
\ ? sneak#streak#to(s, sneak#util#isvisualop(a:op), a:reverse): ""
\ ? sneak#streak#to(s, is_v, a:reverse): ""

if is_op && a:op !=# 'y'
"TODO: account for 't'/inclusive/exclusive
let change = a:op !=? "c" ? "" : "\<c-r>.\<esc>"
let rpt_input = a:input . (a:inputlen > sneak#util#strlen(a:input) ? "\<cr>" : "")
silent! call repeat#set(a:op."\<Plug>SneakRepeat".a:inputlen.a:reverse.a:inclusive.(2*!empty(target)).rpt_input.target.change, a:count)
Expand Down

0 comments on commit 0e5436b

Please sign in to comment.