]> git.gir.st - VimFx.git/blob - extension/packages/vim.coffee
Merge branch 'develop' of github.com:akhodakivskiy/VimFx into develop
[VimFx.git] / extension / packages / vim.coffee
1 utils = require 'utils'
2
3 commands = require 'commands'
4
5 { getPref
6 , isCommandDisabled
7 } = require 'prefs'
8
9 MODE_NORMAL = 1
10 MODE_HINTS = 2
11
12 class Vim
13 @findStr = ''
14
15 constructor: (@window) ->
16 @mode = MODE_NORMAL
17 @keys = []
18 @lastKeyStr = null
19 @markers = undefined
20 @cb = undefined
21 @findRng = null
22 @suppress = false
23
24 Object.defineProperty(this, 'findStr',
25 get: -> return Vim.findStr
26 set: (value) -> Vim.findStr = value
27 )
28
29 enterHintsMode: (@markers, @cb) ->
30 @mode = MODE_HINTS
31
32 # TODO: This function should probably remove
33 # hint markers (if they are present) as well
34 enterNormalMode: ->
35 @mode = MODE_NORMAL
36 @markers = @cb = undefined
37
38 handleKeyDown: (event, keyStr) ->
39 @suppress = true
40 if @mode == MODE_NORMAL || keyStr == 'Esc'
41 @keys.push(keyStr)
42 @lastKeyStr = keyStr
43 if command = commands.findCommand(@keys)
44 command.func(@)
45 return command.name != 'Esc'
46 else if commands.maybeCommand(@keys)
47 return true
48 else
49 @keys.length = 0
50 else if @mode == MODE_HINTS and not (event.ctrlKey or event.metaKey)
51 if utils.getHintChars().search(utils.regexpEscape(keyStr)) > -1
52 commands.hintCharHandler(@, keyStr)
53 return true
54
55 @suppress = false
56 @keys.length = 0
57 return false
58
59 handleKeyPress: (event, keyStr) ->
60 return @lastKeyStr != 'Esc' and @suppress
61
62 handleKeyUp: (event) ->
63 sup = @suppress
64 @suppress = false
65 return @lastKeyStr != 'Esc' and sup
66
67 exports.Vim = Vim
Imprint / Impressum