mirror of
https://github.com/atom/atom.git
synced 2026-02-08 21:55:05 -05:00
Don't insert characters in vim command mode
GlobalKeymap.bindKey can take a selector and a custom function that maps key events to commands. If it returns false, no command is triggered but event propagation is halted.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
_ = require 'underscore'
|
||||
$ = require 'jquery'
|
||||
Specificity = require 'specificity'
|
||||
|
||||
@@ -11,13 +12,19 @@ class BindingSet
|
||||
'=': 187, ';': 186, '\'': 222, '[': 219, ']': 221, '\\': 220
|
||||
|
||||
selector: null
|
||||
bindings: null
|
||||
bindingMap: null
|
||||
bindingFunction: null
|
||||
|
||||
constructor: (@selector, @bindings) ->
|
||||
constructor: (@selector, mapOrFunction) ->
|
||||
if _.isFunction(mapOrFunction)
|
||||
@bindingFunction = mapOrFunction
|
||||
else
|
||||
@bindingMap = mapOrFunction
|
||||
@specificity = Specificity(@selector)
|
||||
|
||||
commandForEvent: (event) ->
|
||||
for pattern, command of @bindings
|
||||
return @bindingFunction(event) if @bindingFunction
|
||||
for pattern, command of @bindingMap
|
||||
return command if @eventMatchesPattern(event, pattern)
|
||||
null
|
||||
|
||||
|
||||
@@ -18,9 +18,12 @@ class GlobalKeymap
|
||||
candidateBindingSets = @bindingSets.filter (set) -> currentNode.is(set.selector)
|
||||
candidateBindingSets.sort (a, b) -> b.specificity - a.specificity
|
||||
for bindingSet in candidateBindingSets
|
||||
if command = bindingSet.commandForEvent(event)
|
||||
command = bindingSet.commandForEvent(event)
|
||||
if command
|
||||
@triggerCommandEvent(event, command)
|
||||
return false
|
||||
else if command == false
|
||||
return false
|
||||
currentNode = currentNode.parent()
|
||||
true
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ class VimMode
|
||||
|
||||
constructor: (@editor) ->
|
||||
@opStack = []
|
||||
atom.bindKeys '.command-mode', > false
|
||||
atom.bindKeys '.command-mode', @commandModeBindings()
|
||||
atom.bindKeys '.insert-mode', '<esc>': 'command-mode:activate'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user