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

Fix key modifiers #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
109 changes: 51 additions & 58 deletions lib/keyboard_shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,149 +90,142 @@ var keyboard_shortcuts = function(spec, my) {
// @event {object} keyboard event
// ```
handler = function(evt) {
var modifier = (1 << 1); /* ctrl */
var modifier_key = 17;
if(process.platform === 'darwin') {
modifier = (1 << 3); /* command */
modifier_key = 91;
}
/* Use for ctrl shortcut on darwin. */
var ctrl = (1 << 1); /* ctrl */
var ctrl_key = 17;
common.log.out(JSON.stringify(evt));

var ControlKey = 17;

//common.log.out(JSON.stringify(evt));
var ShiftMod = (1 << 0);
var ControlMod = (1 << 1);
var AltMod = (1 << 2);
var MetaMod = (1 << 3);

if(evt.type === 7 && (evt.modifiers === modifier) &&
evt.keycode === 84) {
/* Ctrl - T ; Repetition OK */
that.emit('new');
if(process.platform == 'darwin'){
ControlMod = MetaMod;
ControlKey = 91;
}
if(evt.type === 7 && (evt.modifiers === (1 << 0 | modifier)) &&

var ShiftControlMod = ShiftMod | ControlMod;

if(evt.type === 7 && ((evt.modifiers & ShiftControlMod) === ShiftControlMod) &&
evt.keycode === 84 && !is_last(evt)) {
/* Ctrl - Shift - T ; No Repetition */
that.emit('recover');
}

if(evt.type === 7 && (evt.modifiers === modifier) &&
else if(evt.type === 7 && ((evt.modifiers & ControlMod) === ControlMod) &&
evt.keycode === 84) {
/* Ctrl - T ; Repetition OK */
that.emit('new');
}
else if(evt.type === 7 && ((evt.modifiers & ControlMod) === ControlMod) &&
(evt.keycode === 76 || evt.keycode === 32) && !is_last(evt)) {
/* Ctrl - L | Space ; No Repetition */
that.emit('go');
}

if(evt.type === 7 && (evt.modifiers === modifier) &&
else if(evt.type === 7 && ((evt.modifiers & ShiftControlMod) === ShiftControlMod) &&
evt.keycode === 74 && !is_last(evt)) {
/* Ctrl - Shift - J ; No Repetition */
that.emit('back');
}
else if(evt.type === 7 && ((evt.modifiers & ShiftControlMod) === ShiftControlMod) &&
evt.keycode === 75 && !is_last(evt)) {
/* Ctrl - Shift - K ; No Repetition */
that.emit('forward');
}
else if(evt.type === 7 && ((evt.modifiers & ControlMod) === ControlMod) &&
(evt.keycode === 74 || evt.keycode === 40)) {
/* Ctrl - J | Down ; Repetition OK */
that.emit('next');
my.can_commit = true;
}
if(evt.type === 7 && (evt.modifiers === modifier) &&
else if(evt.type === 7 && ((evt.modifiers & ControlMod) === ControlMod) &&
(evt.keycode === 75 || evt.keycode === 38)) {
/* Ctrl - K | Up ; Repetition OK */
that.emit('prev');
my.can_commit = true;
}
if(evt.type === 9 && (evt.modifiers === ctrl) &&
else if(evt.type === 9 && ((evt.modifiers & ShiftControlMod) === ShiftControlMod) &&
(evt.keycode === 9)) {
/* Ctrl - Tab ; Repetition OK */
that.emit('next');
/* Ctrl - Shift - Tab ; Repetition OK */
that.emit('prev');
my.can_commit = true;
}
if(evt.type === 7 && (evt.modifiers === (1 << 0 | ctrl)) &&
else if(evt.type === 9 && ((evt.modifiers & ControlMod) === ControlMod) &&
(evt.keycode === 9)) {
/* Ctrl - Shift - Tab ; Repetition OK */
that.emit('prev');
/* Ctrl - Tab ; Repetition OK */
that.emit('next');
my.can_commit = true;
}
if(evt.type === 7 && (evt.modifiers === modifier) &&
else if(evt.type === 7 && ((evt.modifiers & ControlMod) === ControlMod) &&
(evt.keycode >= 49 && evt.keycode <= 57)) {
/* Ctrl - 1-9 ; Repetiton OK */
that.emit('select_by_index', evt.keycode - 49);
my.can_commit = true;
}

if(evt.type === 7 && (evt.modifiers === (1 << 0 | modifier)) &&
evt.keycode === 74 && !is_last(evt)) {
/* Ctrl - Shift - J ; No Repetition */
that.emit('back');
}
if(evt.type === 7 && (evt.modifiers === (1 << 0 | modifier)) &&
evt.keycode === 75 && !is_last(evt)) {
/* Ctrl - Shift - K ; No Repetition */
that.emit('forward');
}
if(evt.type === 7 && (evt.modifiers === modifier) &&
else if(evt.type === 7 && ((evt.modifiers & ControlMod) === ControlMod) &&
evt.keycode === 37 && !is_last(evt)) {
/* Ctrl - Left ; No Repetition */
that.emit('back');
}
if(evt.type === 7 && (evt.modifiers === modifier) &&
else if(evt.type === 7 && ((evt.modifiers & ControlMod) === ControlMod) &&
evt.keycode === 39 && !is_last(evt)) {
/* Ctrl - Right ; No Repetition */
that.emit('forward');
}

if(evt.type === 7 && (evt.modifiers === (1 << 0 | modifier)) &&
else if(evt.type === 7 && ((evt.modifiers & ShiftControlMod) === ShiftControlMod) &&
evt.keycode === 72 && !is_last(evt)) {
/* Ctrl - Shift - H ; No Repetition */
that.emit('toggle');
}

if(evt.type === 9 &&
(evt.keycode === modifier_key ||
evt.keycode === ctrl_key)) {
else if(evt.type === 9 && evt.keycode === ControlKey) {
/* Ctrl (Release); No Repetition */
if(my.can_commit) {
my.can_commit = false;
that.emit('commit');
}
}
/* CapsLock as a Ctrl case */
if(evt.type === 9 && (evt.modifiers === modifier) &&
else if(evt.type === 9 && ((evt.modifiers & ControlMod) === ControlMod) &&
evt.keycode === 20) {
/* Ctrl (Release); No Repetition */
if(my.can_commit) {
my.can_commit = false;
that.emit('commit');
}
}

if(evt.type === 7 && (evt.modifiers === modifier) &&
else if(evt.type === 7 && ((evt.modifiers & ControlMod) === ControlMod) &&
evt.keycode === 87) {
/* Ctrl - W ; Repetition OK */
that.emit('close');
}

if(evt.type === 7 && (evt.modifiers === modifier) &&
else if(evt.type === 7 && ((evt.modifiers & ControlMod) === ControlMod) &&
evt.keycode === 80 && !is_last(evt)) {
/* Ctrl - W ; No Repetition */
that.emit('stack_pin');
}

if(evt.type === 7 && (evt.modifiers === modifier) &&
else if(evt.type === 7 && ((evt.modifiers & ControlMod) === ControlMod) &&
evt.keycode === 70 && !is_last(evt)) {
/* Ctrl - F ; No Repetition */
that.emit('find_in_page');
}
if(evt.type === 7 && (evt.modifiers === modifier) &&
else if(evt.type === 7 && ((evt.modifiers & ControlMod) === ControlMod) &&
evt.keycode === 82 && !is_last(evt)) {
/* Ctrl - R ; No Repetition */
that.emit('reload');
}

if(evt.type === 7 && evt.keycode === 27) {
else if(evt.type === 7 && evt.keycode === 27) {
/* ESC ; Repetition OK */
that.emit('clear');
}

if(process.platform === 'darwin') {

if(evt.type === 7 && (evt.modifiers === (1 << 0 | modifier)) &&
if(evt.type === 7 && ((evt.modifiers & ShiftControlMod) === ShiftControlMod) &&
evt.keycode === 221) {
/* Ctrl - } ; Repetition OK */
that.emit('next');
my.can_commit = true;
}
if(evt.type === 7 && (evt.modifiers === (1 << 0 | modifier)) &&
else if(evt.type === 7 && ((evt.modifiers & ShiftControlMod) === ShiftControlMod) &&
evt.keycode === 219) {
/* Ctrl - { ; Repetition OK */
that.emit('prev');
Expand Down