]> git.r.bdr.sh - rbdr/dotfiles/blame - atom/packages/vim-mode/lib/vim-mode.coffee
Adds atom packages
[rbdr/dotfiles] / atom / packages / vim-mode / lib / vim-mode.coffee
CommitLineData
24c7594d
BB
1{Disposable, CompositeDisposable} = require 'event-kit'
2StatusBarManager = require './status-bar-manager'
3GlobalVimState = require './global-vim-state'
4VimState = require './vim-state'
5settings = require './settings'
6
7module.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) =>
455f099b 19 return if editor.isMini() or @getEditorState(editor)
24c7594d
BB
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
455f099b
BB
31 @disposables.add atom.workspace.onDidChangeActivePaneItem @updateToPaneItem.bind(this)
32
24c7594d
BB
33 @disposables.add new Disposable =>
34 @vimStates.forEach (vimState) -> vimState.destroy()
35
36 deactivate: ->
37 @disposables.dispose()
38
39 getGlobalState: ->
40 @globalVimState
41
42 getEditorState: (editor) ->
43 @vimStatesByEditor.get(editor)
44
45 consumeStatusBar: (statusBar) ->
46 @statusBarManager.initialize(statusBar)
47 @statusBarManager.attach()
48 @disposables.add new Disposable =>
49 @statusBarManager.detach()
50
455f099b
BB
51 updateToPaneItem: (item) ->
52 vimState = @getEditorState(item) if item?
53 if vimState?
54 vimState.updateStatusBar()
55 else
56 @statusBarManager.hide()
57
24c7594d
BB
58 provideVimMode: ->
59 getGlobalState: @getGlobalState.bind(this)
60 getEditorState: @getEditorState.bind(this)