Skip to content

Commit 40d5d19

Browse files
committed
label-mode: consider g:sneak#absolute_dir = 1 for <Tab>
With absolute_dir, <Tab> and <BS> works exactly like ; , and clever-s would: <Tab> always forward and <BS> always backwards.
1 parent 2b2d12e commit 40d5d19

File tree

3 files changed

+110
-11
lines changed

3 files changed

+110
-11
lines changed

autoload/sneak/label.vim

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ endf
5656

5757
func! sneak#label#to(s, v, label) abort
5858
let seq = ""
59-
" TODO: handle g:sneak#absolute_dir=1
6059
let forward = !a:s._reverse
6160
while 1
62-
let choice = s:do_label(a:s, a:v, a:s._reverse, forward, a:label)
61+
let resolved_forward = g:sneak_opt.absolute_dir ? 1 : forward
62+
let choice = s:do_label(a:s, a:v, a:s._reverse, resolved_forward, a:label)
6363
let seq .= choice
6464
if choice =~# "^\<S-Tab>\\|\<BS>$"
65-
call a:s.init(a:s._input, a:s._repeatmotion, forward ? 1 : 0)
65+
call a:s.init(a:s._input, a:s._repeatmotion, resolved_forward ? 1 : 0)
6666
elseif choice ==# "\<Tab>"
67-
call a:s.init(a:s._input, a:s._repeatmotion, forward ? 0 : 1)
67+
call a:s.init(a:s._input, a:s._repeatmotion, resolved_forward ? 0 : 1)
6868
else
6969
return seq
7070
endif
@@ -110,7 +110,6 @@ func! s:do_label(s, v, reverse, forward, label) abort "{{{
110110
\ : mappedto =~# '<Plug>Sneak\(_;\|Next\)'
111111

112112
if choice =~# "\\v^\<Tab>|\<S-Tab>|\<BS>$" " Decorate next N matches.
113-
" TODO: handle g:sneak#absolute_dir=1
114113
if a:forward
115114
if (!a:reverse && choice ==# "\<Tab>") || (a:reverse && choice =~# "^\<S-Tab>\\|\<BS>$")
116115
call cursor(overflow[0], overflow[1])

doc/sneak.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ g:sneak#absolute_dir = 0
297297
1: Absolute direction. Repeat via |;| or |,| always goes forwards or
298298
backwards respectively.
299299
Note: With |sneak-clever-s|, s and S behave the same as |;| and |,|.
300+
Note: Has the same effect on <Tab> and <BS> / <S-Tab> in label-mode.
300301

301302
g:sneak#use_ic_scs = 0
302303

tests/test.vader

Lines changed: 105 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,21 @@ Given:
748748
I11111111111111111111111111111111111111111111111111111S
749749
J22222222222222222222222222222222222222222222222222222T
750750

751-
Do (label/change-direction/delete):
751+
Do (next labels):
752+
4j9ls22\<Tab>\<Tab>fr-
753+
Expect:
754+
A11111111111111111111111111111111111111111111111111111K
755+
B22222222222222222222222222222222222222222222222222222L
756+
C11111111111111111111111111111111111111111111111111111M
757+
D22222222222222222222222222222222222222222222222222222N
758+
E11111111111111111111111111111111111111111111111111111O
759+
F22222222222222222222222222222222222222222222222222222P
760+
G11111111111111111111111111111111111111111111111111111Q
761+
H2222222222222222222222222222222222222222222222-222222R
762+
I11111111111111111111111111111111111111111111111111111S
763+
J22222222222222222222222222222222222222222222222222222T
764+
765+
Do (next labels, change direction):
752766
4j9ls22\<Tab>\<Tab>\<BS>\<BS>\<BS>\<BS>Rr-
753767
Expect:
754768
A11111111111111111111111111111111111111111111111111111K
@@ -762,7 +776,7 @@ Expect:
762776
I11111111111111111111111111111111111111111111111111111S
763777
J22222222222222222222222222222222222222222222222222222T
764778

765-
Do (label/change-direction/delete/repeat):
779+
Do (next labels, change direction, repeat):
766780
4j9ldz22\<Tab>\<BS>\<BS>N
767781
:\<C-U>doautocmd CursorMoved\<CR>
768782
.
@@ -775,7 +789,7 @@ Expect:
775789
I11111111111111111111111111111111111111111111111111111S
776790
J22222222222222222222222222222222222222222222222222222T
777791

778-
Do (label/backwards/delete):
792+
Do (next labels backwards):
779793
4j9lS22\<Tab>\<Tab>fr-
780794
Expect:
781795
A11111111111111111111111111111111111111111111111111111K
@@ -789,7 +803,7 @@ Expect:
789803
I11111111111111111111111111111111111111111111111111111S
790804
J22222222222222222222222222222222222222222222222222222T
791805

792-
Do (label/backwards/change-direction/delete):
806+
Do (next labels backwards, change direction):
793807
4j9lS22\<Tab>\<Tab>\<BS>\<BS>\<BS>\<BS>Rr-
794808
Expect:
795809
A11111111111111111111111111111111111111111111111111111K
@@ -803,7 +817,7 @@ Expect:
803817
I11111111111111111111111111111111111111111111111111111S
804818
J22222222222222222222222222222222222222222222222222222T
805819

806-
Do (label/backwards/change-direction/delete/repeat):
820+
Do (next labels backwards, change direction, repeat):
807821
4j9ldZ22\<Tab>\<BS>\<BS>N
808822
:\<C-U>doautocmd CursorMoved\<CR>
809823
.
@@ -816,9 +830,94 @@ Expect:
816830
I11111111111111111111111111111111111111111111111111111S
817831
J22222222222222222222222222222222222222222222222222222T
818832

819-
# TODO: g:sneak#absolute_dir=1 tests
833+
Execute (turn on g:sneak#absolute_dir):
834+
let g:sneak#absolute_dir = 1
835+
call SneakReset()
836+
837+
Do (next labels absolute_dir):
838+
4j9ls22\<Tab>\<Tab>fr-
839+
Expect:
840+
A11111111111111111111111111111111111111111111111111111K
841+
B22222222222222222222222222222222222222222222222222222L
842+
C11111111111111111111111111111111111111111111111111111M
843+
D22222222222222222222222222222222222222222222222222222N
844+
E11111111111111111111111111111111111111111111111111111O
845+
F22222222222222222222222222222222222222222222222222222P
846+
G11111111111111111111111111111111111111111111111111111Q
847+
H2222222222222222222222222222222222222222222222-222222R
848+
I11111111111111111111111111111111111111111111111111111S
849+
J22222222222222222222222222222222222222222222222222222T
850+
851+
Do (next labels absolute_dir, change direction):
852+
4j9ls22\<Tab>\<Tab>\<BS>\<BS>\<BS>\<BS>Rr-
853+
Expect:
854+
A11111111111111111111111111111111111111111111111111111K
855+
B222222222222222222222222-2222222222222222222222222222L
856+
C11111111111111111111111111111111111111111111111111111M
857+
D22222222222222222222222222222222222222222222222222222N
858+
E11111111111111111111111111111111111111111111111111111O
859+
F22222222222222222222222222222222222222222222222222222P
860+
G11111111111111111111111111111111111111111111111111111Q
861+
H22222222222222222222222222222222222222222222222222222R
862+
I11111111111111111111111111111111111111111111111111111S
863+
J22222222222222222222222222222222222222222222222222222T
864+
865+
Do (next labels absolute_dir, change direction, repeat):
866+
4j9ldz22\<Tab>\<BS>\<BS>N
867+
:\<C-U>doautocmd CursorMoved\<CR>
868+
.
869+
Expect:
870+
A11111111111111111111111111111111111111111111111111111K
871+
B2222222222222222222222222222222222222222111111111111111111111111111111111111111111111O
872+
F22222222222222222222222222222222222222222222222222222P
873+
G11111111111111111111111111111111111111111111111111111Q
874+
H22222222222222222222222222222222222222222222222222222R
875+
I11111111111111111111111111111111111111111111111111111S
876+
J22222222222222222222222222222222222222222222222222222T
877+
878+
Do (next labels absolute_dir backwards):
879+
4j9lS22\<Tab>\<Tab>fr-
880+
Expect:
881+
A11111111111111111111111111111111111111111111111111111K
882+
B22222222222222222222222222222222222222222222222222222L
883+
C11111111111111111111111111111111111111111111111111111M
884+
D22222222222222222222222222222222222222222222222222222N
885+
E11111111111111111111111111111111111111111111111111111O
886+
F22222222222222222222222222222222222222222222222222-22P
887+
G11111111111111111111111111111111111111111111111111111Q
888+
H22222222222222222222222222222222222222222222222222222R
889+
I11111111111111111111111111111111111111111111111111111S
890+
J22222222222222222222222222222222222222222222222222222T
891+
892+
Do (next labels absolute_dir backwards, change direction):
893+
4j9lS22\<Tab>\<Tab>\<BS>\<BS>\<BS>Rr-
894+
Expect:
895+
A11111111111111111111111111111111111111111111111111111K
896+
B2222222222222222222222-222222222222222222222222222222L
897+
C11111111111111111111111111111111111111111111111111111M
898+
D22222222222222222222222222222222222222222222222222222N
899+
E11111111111111111111111111111111111111111111111111111O
900+
F22222222222222222222222222222222222222222222222222222P
901+
G11111111111111111111111111111111111111111111111111111Q
902+
H22222222222222222222222222222222222222222222222222222R
903+
I11111111111111111111111111111111111111111111111111111S
904+
J22222222222222222222222222222222222222222222222222222T
905+
906+
Do (next labels absolute_dir backwards, change direction, repeat):
907+
4j9ldZ22\<Tab>\<BS>N
908+
:\<C-U>doautocmd CursorMoved\<CR>
909+
.
910+
Expect:
911+
A11111111111111111111111111111111111111111111111111111K
912+
B222222222222222222222222222222222222111111111111111111111111111111111111111111111O
913+
F22222222222222222222222222222222222222222222222222222P
914+
G11111111111111111111111111111111111111111111111111111Q
915+
H22222222222222222222222222222222222222222222222222222R
916+
I11111111111111111111111111111111111111111111111111111S
917+
J22222222222222222222222222222222222222222222222222222T
820918

821919
Execute (cleanup):
920+
let g:sneak#absolute_dir = 0
822921
let g:sneak#label = 0
823922
call SneakReset()
824923

0 commit comments

Comments
 (0)