This commit is contained in:
Nathan Sobo
2012-01-12 17:56:49 -08:00
parent a2cf77892d
commit 86d7a91dcd
3 changed files with 11 additions and 15 deletions

View File

@@ -13,7 +13,7 @@ describe "VimMode", ->
it "puts the editor in command-mode initially", ->
expect(editor).toHaveClass 'command-mode'
fdescribe "command-mode", ->
describe "command-mode", ->
it "stops propagation on key events that don't have bindings so that they don't get inserted", ->
event = keydownEvent('\\')
spyOn(event, 'stopPropagation')

View File

@@ -1,5 +1,5 @@
_ = require 'underscore'
$ = require 'jquery'
_ = require 'underscore'
Specificity = require 'specificity'
module.exports =
@@ -12,21 +12,17 @@ class BindingSet
'=': 187, ';': 186, '\'': 222, '[': 219, ']': 221, '\\': 220
selector: null
bindingMap: null
bindingFunction: null
commandForEvent: null
constructor: (@selector, mapOrFunction) ->
if _.isFunction(mapOrFunction)
@bindingFunction = mapOrFunction
else
@bindingMap = mapOrFunction
@specificity = Specificity(@selector)
commandForEvent: (event) ->
return @bindingFunction(event) if @bindingFunction
for pattern, command of @bindingMap
return command if @eventMatchesPattern(event, pattern)
null
if _.isFunction(mapOrFunction)
@commandForEvent = mapOrFunction
else
@commandForEvent = (event) =>
for pattern, command of mapOrFunction
return command if @eventMatchesPattern(event, pattern)
null
eventMatchesPattern: (event, pattern) ->
pattern = @parseKeyPattern pattern

View File

@@ -9,7 +9,7 @@ class VimMode
constructor: (@editor) ->
@opStack = []
atom.bindKeys '.command-mode', > false
atom.bindKeys '.command-mode', -> false
atom.bindKeys '.command-mode', @commandModeBindings()
atom.bindKeys '.insert-mode', '<esc>': 'command-mode:activate'