]> git.gir.st - VimFx.git/blob - extension/packages/modes.coffee
Factor out normal mode into modes.coffee
[VimFx.git] / extension / packages / modes.coffee
1 utils = require 'utils'
2 { mode_hints } = require 'mode-hints/mode-hints'
3 { updateToolbarButton } = require 'button'
4 { commands
5 , searchForMatchingCommand } = 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 runCommand = (command) ->
21 commandStorage = storage.commands[command.name] ?= {}
22 command.func(vim, commandStorage, event)
23
24 { match, exact, command, index } = searchForMatchingCommand(storage.keys)
25
26 if match
27 storage.keys = storage.keys[index..]
28 if exact
29 runCommand(command)
30 return keyStr != 'Esc'
31 else
32 storage.keys.length = 0
33
34
35 modes['insert'] =
36 onEnter: (vim) ->
37 return unless rootWindow = utils.getRootWindow(vim.window)
38 updateToolbarButton(rootWindow, {insertMode: true})
39 onLeave: (vim) ->
40 return unless rootWindow = utils.getRootWindow(vim.window)
41 updateToolbarButton(rootWindow, {insertMode: false})
42 utils.blurActiveElement(vim.window)
43 onInput: (vim, storage, keyStr) ->
44
45 modes['hints'] = mode_hints
46
47 exports.modes = modes
Imprint / Impressum