]> git.gir.st - VimFx.git/blob - extension/packages/modes.coffee
Merge branch 'develop' of github.com:akhodakivskiy/VimFx into develop
[VimFx.git] / extension / packages / modes.coffee
1 utils = require 'utils'
2 { mode_hints } = require 'mode-hints/mode-hints'
3 { updateToolbarButton } = require 'button'
4 { searchForMatchingCommand
5 , isEscCommandKey } = require 'commands'
6
7 modes = {}
8
9 modes['normal'] =
10 onEnter: (vim, storage, args) ->
11 storage.keys ?= []
12 storage.commands ?= {}
13
14 onLeave: (vim, storage, args) ->
15 storage.keys.length = 0
16
17 onInput: (vim, storage, keyStr, event) ->
18 storage.keys.push(keyStr)
19
20 { match, exact, command } = searchForMatchingCommand(storage.keys)
21
22 if match
23 if exact
24 commandStorage = storage.commands[command.name] ?= {}
25 command.func(vim, commandStorage, event)
26 storage.keys.length = 0
27 return true
28 else
29 storage.keys.length = 0
30
31 modes['insert'] =
32 onEnter: (vim) ->
33 return unless rootWindow = utils.getRootWindow(vim.window)
34 updateToolbarButton(rootWindow, {insertMode: true})
35 onLeave: (vim) ->
36 return unless rootWindow = utils.getRootWindow(vim.window)
37 updateToolbarButton(rootWindow, {insertMode: false})
38 utils.blurActiveElement(vim.window)
39 onInput: (vim, storage, keyStr) ->
40 if isEscCommandKey(keyStr)
41 vim.enterMode('normal')
42 return true
43
44 modes['hints'] = mode_hints
45
46 exports.modes = modes
Imprint / Impressum