   # target is `.defaultTarget` if that property is assigned on the keymap.
   #
   # * `event` A `KeyboardEvent` of type 'keydown'
-  handleKeyboardEvent: (event) ->
+  handleKeyboardEvent: (event, isReplay) ->
+    eventResult = @_handleKeyboardEvent(event, @queuedKeystrokes)
+    return unless eventResult?
+    {keystroke, queuedKeystrokes, exactMatch, partialMatches} = eventResult
+
+    hasPartialMatches = partialMatches? and partialMatches.length > 0
+
+    @queuedKeystrokes.push(keystroke)
+    @queuedKeyboardEvents.push(event)
+
+    if queuedKeystrokes?
+      if hasPartialMatches
+        enableTimeout = (
+          @pendingStateTimeoutHandle? or
+          exactMatch? or
+          characterForKeyboardEvent(@queuedKeyboardEvents[0])?
+        )
+        enableTimeout = false if isReplay
+        @enterPendingState(partialMatches, enableTimeout)
+    else if not exactMatch? and not hasPartialMatches and @pendingPartialMatches?
+      @terminatePendingState()
+    else
+      @clearQueuedKeystrokes()
+
+  _handleKeyboardEvent: (event, queuedKeystrokes=[]) ->
     keystroke = @keystrokeForKeyboardEvent(event)
 
-    if event.type isnt 'keyup' and @queuedKeystrokes.length > 0 and isAtomModifier(keystroke)
+    if event.type isnt 'keyup' and queuedKeystrokes.length > 0 and isAtomModifier(keystroke)
       event.preventDefault()
       return
-
-    @queuedKeyboardEvents.push(event)
-    @queuedKeystrokes.push(keystroke)
-    keystrokes = @queuedKeystrokes.join(' ')
 
     # If the event's target is document.body, assign it to defaultTarget instead
     # to provide a catch-all element when nothing is focused.
     target = event.target
     target = @defaultTarget if event.target is document.body and @defaultTarget?
 
+    queuedKeystrokes = queuedKeystrokes.concat([keystroke])
+    keystrokes = queuedKeystrokes.join(' ')
+
     # First screen for any bindings that match the current keystrokes,
     # regardless of their current selector. Matching strings is cheaper than
     # matching selectors.
-    {partialMatchCandidates, exactMatchCandidates} = @findMatchCandidates(@queuedKeystrokes)
+    {partialMatchCandidates, keydownExactMatchCandidates, exactMatchCandidates} = @findMatchCandidates(queuedKeystrokes)
+    exactMatch = null
     partialMatches = @findPartialMatches(partialMatchCandidates, target)
 
     # Determine if the current keystrokes match any bindings *exactly*. If we

    # state with a timeout.
    if exactMatchCandidates.length > 0
      currentTarget = target
      while currentTarget? and currentTarget isnt document
        exactMatches = @findExactMatches(exactMatchCandidates, currentTarget)
        for exactMatch in exactMatches
          if exactMatch.command is 'native!'
            @clearQueuedKeystrokes()
            return

          if exactMatch.command is 'abort!'
            @clearQueuedKeystrokes()
            event.preventDefault()
            return

          if exactMatch.command is 'unset!'
            break

          foundMatch = true
          break if partialMatches.length > 0
          @clearQueuedKeystrokes()
          @cancelPendingState()
          if @dispatchCommandEvent(exactMatch.command, target, event)
            @emitter.emit 'did-match-binding', {
              keystrokes,
              eventType: event.type,
              binding: exactMatch,
              keyboardEventTarget: target
            }
            return
        currentTarget = currentTarget.parentElement

    # If we're at this point in the method, we either found no matches for the

  findMatchCandidates: (keystrokeArray) ->
    partialMatchCandidates = []
    exactMatchCandidates = []
    keydownExactMatchCandidates = []

    for binding in @keyBindings when binding.enabled
      doesMatch = keystrokesMatch(binding.keystrokeArray, keystrokeArray)
