Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider HOME and END keys as movement keys #378

Merged
merged 1 commit into from
Apr 27, 2016
Merged
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
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());
});