Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Don't replay events when all matches have only keyup suffixes #205

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions spec/keymap-manager-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 6 additions & 5 deletions src/keymap-manager.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down