 
     !isMultiKeystroke
 
-  bindingSetsForNode: (node) ->
-    bindingSets = @bindingSets.filter (set) -> node.is(set.selector)
+  bindingSetsForNode: (node, candidateBindingSets = @bindingSets) ->
+    bindingSets = candidateBindingSets.filter (set) -> node.is(set.selector)
     bindingSets.sort (a, b) ->
       if b.specificity == a.specificity
         b.index - a.index

    event.keystrokes = @multiKeystrokeStringForEvent(event)
    isMultiKeystroke = @queuedKeystrokes?
    @queuedKeystrokes = null
    currentNode = $(event.target)
    while currentNode.length
      candidateBindingSets = @bindingSetsForNode(currentNode)
      for bindingSet in candidateBindingSets
        command = bindingSet.commandForEvent(event)
        if command

module.exports =
class Keymap
  bindingSets: null
  bindingSetsByFirstKeystroke: null
  queuedKeystrokes: null

  constructor: ->
    @bindingSets = []
    @bindingSetsByFirstKeystroke = {}

  bindDefaultKeys: ->
    @bindKeys "*",
