]> git.gir.st - VimFx.git/blob - extension/packages/vim.coffee
Remove default argument value
[VimFx.git] / extension / packages / vim.coffee
1 utils = require 'utils'
2 { modes } = require 'modes'
3 { isEscCommandKey } = require 'commands'
4
5 class Vim
6 constructor: (@window) ->
7 @storage = {}
8 @enterMode('normal')
9
10 enterMode: (mode, args) ->
11 # `args` is an array of arguments to be passed to the mode's `onEnter` method
12 if mode not of modes
13 throw new Error("Not a valid VimFx mode to enter: #{ mode }")
14
15 if @mode != mode
16 if @mode of modes
17 modes[@mode].onLeave(@, @storage[@mode], args)
18
19 @mode = mode
20
21 modes[@mode].onEnter(@, @storage[@mode] ?= {}, args)
22
23 onInput: (keyStr, event) ->
24 isEditable = utils.isElementEditable(event.originalTarget)
25
26 if isEditable and not isEscCommandKey(keyStr)
27 return false
28
29 oldMode = @mode
30
31 suppress = modes[@mode]?.onInput(@, @storage[@mode], keyStr, event)
32
33 if oldMode == 'normal' and keyStr == 'Esc'
34 return false
35 else
36 return suppress
37
38 exports.Vim = Vim
Imprint / Impressum