]> git.gir.st - VimFx.git/blob - extension/packages/modes.coffee
Fix a likely future bug
[VimFx.git] / extension / packages / modes.coffee
1 utils = require 'utils'
2 hints = require 'hints'
3
4 mode_hints =
5 enter: (vim, storage, [ markers, cb ]) ->
6 storage.markers = markers
7 storage.cb = cb
8
9 handleKeyDown: (vim, storage, event, keyStr) ->
10 if utils.getHintChars().search(utils.regexpEscape(keyStr)) > -1
11 @hintCharHandler(vim, storage, keyStr)
12 return true
13
14 onEnterNormalMode: (vim, storage) ->
15 hints.removeHints(vim.window.document)
16 storage.markers = storage.cb = undefined
17
18 # Processes the char, updates and hides/shows markers
19 hintCharHandler: (vim, storage, keyStr) ->
20 if keyStr
21 # Get char and escape it to avoid problems with String.search
22 key = utils.regexpEscape(keyStr)
23
24 { markers, cb } = storage
25
26 # First do a pre match - count how many markers will match with the new character entered
27 if markers.reduce(((v, marker) -> v or marker.willMatch(key)), false)
28 for marker in markers
29 marker.matchHintChar(key)
30
31 if marker.isMatched()
32 # Add element features to the bloom filter
33 marker.reward()
34 cb(marker)
35 vim.enterNormalMode()
36 break
37
38 modes =
39 hints: mode_hints
40
41 exports.modes = modes
Imprint / Impressum