]> git.gir.st - VimFx.git/blob - extension/packages/vim.coffee
enering/leaving modes tweaks
[VimFx.git] / extension / packages / vim.coffee
1 { modes } = require 'modes'
2 { isEscCommandKey } = require 'commands'
3
4 class Vim
5 constructor: (@window) ->
6 @storage = {}
7 @enterMode('normal')
8
9 enterMode: (mode, args) ->
10 # `args` is an array of arguments to be passed to the mode's `onEnter` method
11 if mode not of modes
12 throw new Error("Not a valid VimFx mode to enter: #{ mode }")
13
14 if @mode != mode
15 if @mode of modes
16 modes[@mode].onLeave(@, @storage[@mode], args)
17
18 @mode = mode
19
20 modes[@mode].onEnter(@, @storage[@mode] ?= {}, args)
21
22 onInput: (keyStr, event, options = {}) ->
23 if options.autoInsertMode and not isEscCommandKey(keyStr)
24 return false
25
26 return modes[@mode]?.onInput(@, @storage[@mode], keyStr, event)
27
28 exports.Vim = Vim
Imprint / Impressum