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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from atom/io-modifier-keyups
Improve reliability of catching modifier key-up events
- Loading branch information
Showing
8 changed files
with
297 additions
and
110 deletions.
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') | ||
|
||
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.