Skip to content

Commit 7befa0a

Browse files
committed
Do not trigger fallback mapping if not mapped
Check if the maps exist first.
1 parent 49a4219 commit 7befa0a

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

autoload/cycle.vim

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,14 @@ function! cycle#new(class_name, direction, count, ...) "{{{
7575
let matches = cycle#search(a:class_name, {'direction': a:direction, 'count': a:count, 'groups': groups})
7676

7777
if empty(matches)
78-
return s:fallback(
79-
\ a:class_name == 'v' ? "'<,'>" : '',
80-
\ a:direction,
81-
\ a:count
82-
\ )
78+
if len(mapcheck('<Plug>CycleFallback')) > 0
79+
call s:fallback(
80+
\ a:class_name == 'v' ? "'<,'>" : '',
81+
\ a:direction,
82+
\ a:count
83+
\ )
84+
endif
85+
return
8386
endif
8487

8588
let ctx = {

test/fallback.vimspec

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Describe Fallback
2+
Before each
3+
new
4+
End
5+
6+
After each
7+
if len(mapcheck('<Plug>CycleFallbackNext')) > 0
8+
unmap <Plug>CycleFallbackNext
9+
endif
10+
bwipeout!
11+
End
12+
13+
It does nothing by default
14+
call setline(1, '200')
15+
execute 'normal \a'
16+
Assert Equals(getline(1), '200')
17+
End
18+
19+
It triggers fallback mapping in Normal mode
20+
noremap <silent> <Plug>CycleFallbackNext <C-A>
21+
22+
call setline(1, '200')
23+
execute 'normal \a'
24+
25+
Assert Equals(getline(1), '201')
26+
End
27+
End

0 commit comments

Comments
 (0)