Skip to content

Commit

Permalink
Consider HOME and END keys as movement keys
Browse files Browse the repository at this point in the history
fixes #377
  • Loading branch information
bantic committed Apr 27, 2016
1 parent 651bc57 commit c4b2c51
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/js/utils/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const Key = class Key {
}

isMovement() {
return this.isArrow();
return this.isArrow() || this.isHome() || this.isEnd();
}

isArrow() {
Expand All @@ -120,6 +120,14 @@ const Key = class Key {
return this.keyCode === Keycodes.RIGHT;
}

isHome() {
return this.keyCode === Keycodes.HOME;
}

isEnd() {
return this.keyCode === Keycodes.END;
}

get direction() {
switch (true) {
case this.isDelete():
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/utils/key-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,23 @@ test('firefox arrow keypress is not printable', (assert) => {
let key = Key.fromEvent(event);
assert.ok(!key.isPrintable());
});

test('HOME key is movement', (assert) => {
let element = $('#qunit-fixture')[0];
let event = Helpers.dom.createMockEvent('keypress', element, {
keyCode: Keycodes.HOME,
charCode: 0
});
let key = Key.fromEvent(event);
assert.ok(key.isMovement());
});

test('END key is movement', (assert) => {
let element = $('#qunit-fixture')[0];
let event = Helpers.dom.createMockEvent('keypress', element, {
keyCode: Keycodes.END,
charCode: 0
});
let key = Key.fromEvent(event);
assert.ok(key.isMovement());
});

0 comments on commit c4b2c51

Please sign in to comment.