Skip to content

Commit

Permalink
fixes shiftKey not being detected
Browse files Browse the repository at this point in the history
  • Loading branch information
rlivsey committed Oct 14, 2015
1 parent cbd6ec0 commit 9d515e9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/js/utils/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const Key = class Key {
}

isShift() {
return this.hasModifier(MODIFIERS.SHIFT);
return this.shiftKey;
}

hasModifier(modifier) {
Expand Down Expand Up @@ -97,6 +97,10 @@ const Key = class Key {
return this.event.metaKey;
}

get shiftKey() {
return this.event.shiftKey;
}

isChar(string) {
return this.keyCode === string.toUpperCase().charCodeAt(0);
}
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/utils/key-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Helpers from '../../test-helpers';
import Key from 'content-kit-editor/utils/key';
import { MODIFIERS } from 'content-kit-editor/utils/key';

const {module, test} = Helpers;

module('Unit: Utils: Key');

test('#hasModifier with no modifier', (assert) => {
const key = Key.fromEvent({ keyCode: 42 });

assert.ok(!key.hasModifier(MODIFIERS.META), "META not pressed");
assert.ok(!key.hasModifier(MODIFIERS.CTRL), "CTRL not pressed");
assert.ok(!key.hasModifier(MODIFIERS.SHIFT), "SHIFT not pressed");
});

test('#hasModifier with META', (assert) => {
const key = Key.fromEvent({ metaKey: true });

assert.ok(key.hasModifier(MODIFIERS.META), "META pressed");
assert.ok(!key.hasModifier(MODIFIERS.CTRL), "CTRL not pressed");
assert.ok(!key.hasModifier(MODIFIERS.SHIFT), "SHIFT not pressed");
});

test('#hasModifier with CTRL', (assert) => {
const key = Key.fromEvent({ ctrlKey: true });

assert.ok(!key.hasModifier(MODIFIERS.META), "META not pressed");
assert.ok(key.hasModifier(MODIFIERS.CTRL), "CTRL pressed");
assert.ok(!key.hasModifier(MODIFIERS.SHIFT), "SHIFT not pressed");
});

test('#hasModifier with SHIFT', (assert) => {
const key = Key.fromEvent({ shiftKey: true });

assert.ok(!key.hasModifier(MODIFIERS.META), "META not pressed");
assert.ok(!key.hasModifier(MODIFIERS.CTRL), "CTRL not pressed");
assert.ok(key.hasModifier(MODIFIERS.SHIFT), "SHIFT pressed");
});

0 comments on commit 9d515e9

Please sign in to comment.