This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Improve reliability of catching modifier key-up events #156
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
94fd11b
catching modifier keyups beyond pending timeout
iolsen 53d9c89
fixed style issues from nathansobo's review
iolsen 1888c70
more 🐍 ▶️ 🐫
iolsen faca320
require only one keyup from the keydown sequence
iolsen 5695cc1
stop restricting new behavior to modifier keys
iolsen 070c406
move keystroke matcher to KeyBinding
iolsen c3bcde2
start unifying with keydownExact matches. use MATCH_TYPES everywhere.
iolsen f91f755
reset for simpler new plan. tests all pass.
iolsen c9b32cc
keyup matcher class in progress
iolsen b5d6d15
lint fixes
iolsen 800dc79
PartialKeyupMatcher basically works, has tests
iolsen 8fde502
new behavior works well. old tests need fixing.
iolsen 1bd09a5
existing tests passing
iolsen d77ccbd
one more test. cleanup.
iolsen 13375ee
merged with master
iolsen 4fc8165
lint fixes
iolsen 2e38501
Merge branch 'master' into io-modifier-keyups
iolsen 1ced703
Merge branch 'master' into io-modifier-keyups
iolsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{KeyBinding, MATCH_TYPES} = require '../src/key-binding' | ||
|
||
describe "KeyBinding", -> | ||
describe ".matchesKeystrokes(userKeystrokes)", -> | ||
it "returns 'exact' for exact matches", -> | ||
assert.equal(keyBindingArgHelper('ctrl-tab ^tab ^ctrl').matchesKeystrokes(['ctrl-tab', '^tab', '^ctrl']), 'exact') | ||
assert.equal(keyBindingArgHelper('ctrl-tab ^ctrl').matchesKeystrokes(['ctrl-tab', '^tab', '^ctrl']), 'exact') | ||
assert.equal(keyBindingArgHelper('a b c').matchesKeystrokes(['a', '^a', 'b', '^b', 'c']), 'exact') | ||
assert.equal(keyBindingArgHelper('a b ^b c').matchesKeystrokes(['a', '^a', 'b', '^b', 'c']), 'exact') | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: 🔥 this newline. |
||
it "returns false for non-matches", -> | ||
assert.equal(keyBindingArgHelper('ctrl-tab ^tab').matchesKeystrokes(['ctrl-tab', '^tab', '^ctrl']), false) | ||
assert.equal(keyBindingArgHelper('a b c').matchesKeystrokes(['a', '^a', 'b', '^b', 'c', '^c']), false) | ||
assert.equal(keyBindingArgHelper('a b ^b c').matchesKeystrokes(['a', '^a', 'b', '^b', 'c', '^c']), false) | ||
|
||
assert.equal(keyBindingArgHelper('a').matchesKeystrokes(['a', '^a', 'b', '^b', 'c', '^c']), false) | ||
assert.equal(keyBindingArgHelper('a').matchesKeystrokes(['a', '^a']), false) | ||
assert.equal(keyBindingArgHelper('a c').matchesKeystrokes(['a', '^a', 'b', '^b', 'c', '^c']), false) | ||
assert.equal(keyBindingArgHelper('a b ^d').matchesKeystrokes(['a', '^a', 'b', '^b', 'c', '^c']), false) | ||
assert.equal(keyBindingArgHelper('a d ^d').matchesKeystrokes(['a', '^a', 'b', '^b', 'c', '^c']), false) | ||
assert.equal(keyBindingArgHelper('a d ^d').matchesKeystrokes(['^c']), false) | ||
|
||
it "returns 'partial' for partial matches", -> | ||
assert.equal(keyBindingArgHelper('a b ^b').matchesKeystrokes(['a']), 'partial') | ||
assert.equal(keyBindingArgHelper('a b c').matchesKeystrokes(['a']), 'partial') | ||
assert.equal(keyBindingArgHelper('a b c').matchesKeystrokes(['a', '^a']), 'partial') | ||
assert.equal(keyBindingArgHelper('a b c').matchesKeystrokes(['a', '^a', 'b']), 'partial') | ||
assert.equal(keyBindingArgHelper('a b c').matchesKeystrokes(['a', '^a', 'b', '^b']), 'partial') | ||
assert.equal(keyBindingArgHelper('a b c').matchesKeystrokes(['a', '^a', 'd', '^d']), false) | ||
|
||
it "returns MATCH_TYPES.PENDING_KEYUP for bindings that match and contain a remainder of only keyup events", -> | ||
assert.equal(keyBindingArgHelper('a b ^b').matchesKeystrokes(['a', 'b']), MATCH_TYPES.PENDING_KEYUP) | ||
|
||
keyBindingArgHelper = (binding) -> | ||
return new KeyBinding('test', 'test', binding, 'body', 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** @babel */ | ||
/* eslint-env mocha */ | ||
/* global assert */ | ||
|
||
const PartialKeyupMatcher = require('../src/partial-keyup-matcher.js') | ||
import {KeyBinding} from '../src/key-binding' | ||
|
||
describe('PartialKeyupMatcher', () => { | ||
it('returns a simple single-modifier-keyup match', () => { | ||
const matcher = new PartialKeyupMatcher() | ||
const kb = keyBindingArgHelper('ctrl-tab ^ctrl') | ||
matcher.addPendingMatch(kb) | ||
const matches = matcher.getMatches('^ctrl') | ||
assert.equal(matches.length, 1) | ||
assert.equal(matches[0], kb) | ||
it('removes match returned', () => { | ||
const matches = matcher.getMatches('^ctrl') | ||
assert.equal(matches.length, 0) | ||
}) | ||
}) | ||
|
||
it('does not match multiple keyup binding on single keyup events', () => { | ||
const matcher = new PartialKeyupMatcher() | ||
const kb = keyBindingArgHelper('ctrl-shift-tab ^ctrl-shift') | ||
matcher.addPendingMatch(kb) | ||
let matches = matcher.getMatches('^ctrl') | ||
assert.equal(matches.length, 0) | ||
matches = matcher.getMatches('^shift') | ||
assert.equal(matches.length, 0) | ||
}) | ||
|
||
it('for multi-keystroke bindings, matches only when all keyups are received', () => { | ||
const matcher = new PartialKeyupMatcher() | ||
const kb = keyBindingArgHelper('ctrl-shift-tab ^ctrl ^shift') | ||
matcher.addPendingMatch(kb) | ||
matches = matcher.getMatches('^shift') // no-op should return no match | ||
assert.equal(matches.length, 0) | ||
// should return no match but set state to match on next ^ctrl | ||
let matches = matcher.getMatches('^ctrl') | ||
assert.equal(matches.length, 0) | ||
matches = matcher.getMatches('^shift') | ||
assert.equal(matches.length, 1) | ||
assert.equal(matches[0], kb) | ||
it('removes match returned', () => { | ||
const matches = matcher.getMatches('^ctrl') | ||
assert.equal(matches.length, 0) | ||
}) | ||
}) | ||
}) | ||
|
||
function keyBindingArgHelper (binding) { | ||
return new KeyBinding('test', 'test', binding, 'body', 0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Should insert an empty line above this second
it
.