]> git.gir.st - VimFx.git/blob - extension/packages/vim.coffee
Merge pull request #177 from lydell/better-options
[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 specialKeys = ['Shift-Space', 'Space', 'Backspace']
52 if utils.getHintChars().search(utils.regexpEscape(keyStr)) > -1 or keyStr in specialKeys
53 commands.hintCharHandler(@, keyStr)
54 return true
55
56 @suppress = false
57 @keys.length = 0
58 return false
59
60 handleKeyPress: (event, keyStr) ->
61 return @lastKeyStr != 'Esc' and @suppress
62
63 handleKeyUp: (event) ->
64 sup = @suppress
65 @suppress = false
66 return @lastKeyStr != 'Esc' and sup
67
68 exports.Vim = Vim
Imprint / Impressum