diff --git a/spec/keymap-manager-spec.coffee b/spec/keymap-manager-spec.coffee index 2a5bd6b..a382759 100644 --- a/spec/keymap-manager-spec.coffee +++ b/spec/keymap-manager-spec.coffee @@ -465,6 +465,44 @@ describe "KeymapManager", -> getFakeClock().tick(keymapManager.getPartialMatchTimeout()) assert.deepEqual(events, ['abc-secret-code']) + it "does not replay any keystrokes due to the keyup suffix", -> + keymapManager.add "test", + "div.a": + "ctrl-y": "y-command-2" + elementA.addEventListener 'y-command-2', (e) -> events.push('y-keydown') + + keymapManager.handleKeyboardEvent(buildKeydownEvent(key: 'y', ctrlKey: true, target: elementA)) + getFakeClock().tick(keymapManager.getPartialMatchTimeout()) + assert.deepEqual(events, ['y-keydown']) + keymapManager.handleKeyboardEvent(buildKeyupEvent(key: 'y', target: elementA)) + getFakeClock().tick(keymapManager.getPartialMatchTimeout()) + assert.deepEqual(events, ['y-keydown']) + keymapManager.handleKeyboardEvent(buildKeyupEvent(key: 'Control', target: elementA)) + getFakeClock().tick(keymapManager.getPartialMatchTimeout()) + assert.deepEqual(events, ['y-keydown', 'y-up-ctrl-keyup']) + + it "does not replay any keystrokes due to an alt- keyup suffix either", -> + keymapManager.add "test", + ".a": + "alt-y": "alt-y-command-2" + keymapManager.add "test", + "div.a": + "alt-y": "alt-y-command" + "alt-y ^alt": "alt-y-release-command" + + ['alt-y-command', 'alt-y-release-command', 'alt-y-command-2'].forEach (command) -> + elementA.addEventListener command, (e) -> events.push(command) + + keymapManager.handleKeyboardEvent(buildKeydownEvent(key: 'y', altKey: true, target: elementA)) + getFakeClock().tick(keymapManager.getPartialMatchTimeout()) + assert.deepEqual(events, ['alt-y-command']) + keymapManager.handleKeyboardEvent(buildKeyupEvent(key: 'y', target: elementA)) + getFakeClock().tick(keymapManager.getPartialMatchTimeout()) + assert.deepEqual(events, ['alt-y-command']) + keymapManager.handleKeyboardEvent(buildKeyupEvent(key: 'Alt', target: elementA)) + getFakeClock().tick(keymapManager.getPartialMatchTimeout()) + assert.deepEqual(events, ['alt-y-command', 'alt-y-release-command']) + it "only counts entire keystrokes when checking for partial matches", -> element = $$ -> @div class: 'a' keymapManager.add 'test', diff --git a/src/keymap-manager.coffee b/src/keymap-manager.coffee index c332ba1..11391ef 100644 --- a/src/keymap-manager.coffee +++ b/src/keymap-manager.coffee @@ -530,7 +530,8 @@ class KeymapManager hasPartialMatches = partialMatches.length > 0 shouldUsePartialMatches = hasPartialMatches - if isKeyup(keystroke) + eventIsKeyup = isKeyup(keystroke) + if eventIsKeyup exactMatchCandidates = exactMatchCandidates.concat(@pendingKeyupMatcher.getMatches(keystroke)) # Determine if the current keystrokes match any bindings *exactly*. If we @@ -617,10 +618,10 @@ class KeymapManager @bindingsToDisable.push(dispatchedExactMatch) if dispatchedExactMatch if hasPartialMatches and shouldUsePartialMatches - enableTimeout = ( - @pendingStateTimeoutHandle? or - dispatchedExactMatch? or - characterForKeyboardEvent(@queuedKeyboardEvents[0])? + enableTimeout = @pendingStateTimeoutHandle? or + not allPartialMatchesContainKeyupRemainder and ( + dispatchedExactMatch? or + characterForKeyboardEvent(@queuedKeyboardEvents[0])? and not eventIsKeyup ) enableTimeout = false if replay @enterPendingState(partialMatches, enableTimeout)