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'
8 config: settings.config
11 @disposables = new CompositeDisposable
12 @globalVimState = new GlobalVimState
13 @statusBarManager = new StatusBarManager
16 @vimStatesByEditor = new WeakMap
18 @disposables.add atom.workspace.observeTextEditors (editor) =>
19 return if editor.isMini() or @getEditorState(editor)
21 vimState = new VimState(
22 atom.views.getView(editor),
27 @vimStates.add(vimState)
28 @vimStatesByEditor.set(editor, vimState)
29 vimState.onDidDestroy => @vimStates.delete(vimState)
31 @disposables.add atom.workspace.onDidChangeActivePaneItem @updateToPaneItem.bind(this)
33 @disposables.add new Disposable =>
34 @vimStates.forEach (vimState) -> vimState.destroy()
37 @disposables.dispose()
42 getEditorState: (editor) ->
43 @vimStatesByEditor.get(editor)
45 consumeStatusBar: (statusBar) ->
46 @statusBarManager.initialize(statusBar)
47 @statusBarManager.attach()
48 @disposables.add new Disposable =>
49 @statusBarManager.detach()
51 updateToPaneItem: (item) ->
52 vimState = @getEditorState(item) if item?
54 vimState.updateStatusBar()
56 @statusBarManager.hide()
59 getGlobalState: @getGlobalState.bind(this)
60 getEditorState: @getEditorState.bind(this)