]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/vim-mode/lib/vim-mode.coffee
660fba0cc8e13901e0a650dc0991d5e32ffdd724
[rbdr/dotfiles] / atom / packages / vim-mode / lib / vim-mode.coffee
1 {Disposable, CompositeDisposable} = require 'event-kit'
2 StatusBarManager = require './status-bar-manager'
3 GlobalVimState = require './global-vim-state'
4 VimState = require './vim-state'
5 settings = require './settings'
6
7 module.exports =
8 config: settings.config
9
10 activate: (state) ->
11 @disposables = new CompositeDisposable
12 @globalVimState = new GlobalVimState
13 @statusBarManager = new StatusBarManager
14
15 @vimStates = new Set
16 @vimStatesByEditor = new WeakMap
17
18 @disposables.add atom.workspace.observeTextEditors (editor) =>
19 return if editor.isMini() or @vimStatesByEditor.get(editor)
20
21 vimState = new VimState(
22 atom.views.getView(editor),
23 @statusBarManager,
24 @globalVimState
25 )
26
27 @vimStates.add(vimState)
28 @vimStatesByEditor.set(editor, vimState)
29 vimState.onDidDestroy => @vimStates.delete(vimState)
30
31 @disposables.add new Disposable =>
32 @vimStates.forEach (vimState) -> vimState.destroy()
33
34 deactivate: ->
35 @disposables.dispose()
36
37 getGlobalState: ->
38 @globalVimState
39
40 getEditorState: (editor) ->
41 @vimStatesByEditor.get(editor)
42
43 consumeStatusBar: (statusBar) ->
44 @statusBarManager.initialize(statusBar)
45 @statusBarManager.attach()
46 @disposables.add new Disposable =>
47 @statusBarManager.detach()
48
49 provideVimMode: ->
50 getGlobalState: @getGlobalState.bind(this)
51 getEditorState: @getEditorState.bind(this)