use - for shortcut separators

pull/37/head
Paul Ivanov 12 years ago
parent 083f631cde
commit 4cf1717980

@ -85,25 +85,25 @@ IPython.keyboard = (function (IPython) {
// Put a shortcut into normalized form:
// 1. Make lowercase
// 2. Replace cmd by meta
// 3. Sort '+' separated modifiers into the order alt+ctrl+meta+shift
// 3. Sort '-' separated modifiers into the order alt-ctrl-meta-shift
// 4. Normalize keys
shortcut = shortcut.toLowerCase().replace('cmd', 'meta');
var values = shortcut.split("+");
var values = shortcut.split("-");
if (values.length === 1) {
return normalize_key(values[0]);
} else {
var modifiers = values.slice(0,-1);
var key = normalize_key(values[values.length-1]);
modifiers.sort();
return modifiers.join('+') + '+' + key;
return modifiers.join('-') + '-' + key;
}
};
var shortcut_to_event = function (shortcut, type) {
// Convert a shortcut (shift+r) to a jQuery Event object
// Convert a shortcut (shift-r) to a jQuery Event object
type = type || 'keydown';
shortcut = normalize_shortcut(shortcut);
var values = shortcut.split("+");
var values = shortcut.split("-");
var modifiers = values.slice(0,-1);
var key = values[values.length-1];
var opts = {which: keycodes[key]};
@ -115,13 +115,13 @@ IPython.keyboard = (function (IPython) {
};
var event_to_shortcut = function (event) {
// Convert a jQuery Event object to a shortcut (shift+r)
// Convert a jQuery Event object to a shortcut (shift-r)
var shortcut = '';
var key = inv_keycodes[event.which];
if (event.altKey && key !== 'alt') {shortcut += 'alt+';}
if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl+';}
if (event.metaKey && key !== 'meta') {shortcut += 'meta+';}
if (event.shiftKey && key !== 'shift') {shortcut += 'shift+';}
if (event.altKey && key !== 'alt') {shortcut += 'alt-';}
if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl-';}
if (event.metaKey && key !== 'meta') {shortcut += 'meta-';}
if (event.shiftKey && key !== 'shift') {shortcut += 'shift-';}
shortcut += key;
return shortcut;
};

@ -26,7 +26,7 @@ var IPython = (function (IPython) {
return true;
}
},
'shift+enter' : {
'shift-enter' : {
help : 'run cell, select below',
help_index : 'ba',
handler : function (event) {
@ -34,7 +34,7 @@ var IPython = (function (IPython) {
return false;
}
},
'ctrl+enter' : {
'ctrl-enter' : {
help : 'run cell',
help_index : 'bb',
handler : function (event) {
@ -42,7 +42,7 @@ var IPython = (function (IPython) {
return false;
}
},
'alt+enter' : {
'alt-enter' : {
help : 'run cell, insert below',
help_index : 'bc',
handler : function (event) {
@ -64,7 +64,7 @@ var IPython = (function (IPython) {
}
};
} else {
default_common_shortcuts['ctrl+s'] =
default_common_shortcuts['ctrl-s'] =
{
help : 'save notebook',
help_index : 'fb',
@ -87,7 +87,7 @@ var IPython = (function (IPython) {
return false;
}
},
'ctrl+m' : {
'ctrl-m' : {
help : 'command mode',
help_index : 'ab',
handler : function (event) {
@ -129,7 +129,7 @@ var IPython = (function (IPython) {
}
}
},
'alt+-' : {
'alt--' : {
help : 'split cell',
help_index : 'ea',
handler : function (event) {
@ -137,7 +137,7 @@ var IPython = (function (IPython) {
return false;
}
},
'alt+subtract' : {
'alt-subtract' : {
help : '',
help_index : 'eb',
handler : function (event) {
@ -149,7 +149,7 @@ var IPython = (function (IPython) {
help : 'indent or complete',
help_index : 'ec',
},
'shift+tab' : {
'shift-tab' : {
help : 'tooltip',
help_index : 'ed',
},
@ -172,17 +172,17 @@ var IPython = (function (IPython) {
help_index : 'eg'
};
} else {
default_edit_shortcuts['ctrl+/'] =
default_edit_shortcuts['ctrl-/'] =
{
help : 'toggle comment',
help_index : 'ee'
};
default_edit_shortcuts['ctrl+]'] =
default_edit_shortcuts['ctrl-]'] =
{
help : 'indent',
help_index : 'ef'
};
default_edit_shortcuts['ctrl+['] =
default_edit_shortcuts['ctrl-['] =
{
help : 'dedent',
help_index : 'eg'
@ -264,7 +264,7 @@ var IPython = (function (IPython) {
return false;
}
},
'shift+v' : {
'shift-v' : {
help : 'paste cell above',
help_index : 'eg',
handler : function (event) {
@ -389,7 +389,7 @@ var IPython = (function (IPython) {
return false;
}
},
'shift+o' : {
'shift-o' : {
help : 'toggle output scrolling',
help_index : 'gc',
handler : function (event) {
@ -405,7 +405,7 @@ var IPython = (function (IPython) {
return false;
}
},
'ctrl+j' : {
'ctrl-j' : {
help : 'move cell down',
help_index : 'eb',
handler : function (event) {
@ -413,7 +413,7 @@ var IPython = (function (IPython) {
return false;
}
},
'ctrl+k' : {
'ctrl-k' : {
help : 'move cell up',
help_index : 'ea',
handler : function (event) {
@ -463,7 +463,7 @@ var IPython = (function (IPython) {
return false;
}
},
'shift+m' : {
'shift-m' : {
help : 'merge cell below',
help_index : 'ek',
handler : function (event) {

@ -73,7 +73,7 @@ var IPython = (function (IPython) {
var special_case = { pageup: "PageUp", pagedown: "Page Down" };
var prettify = function (s) {
var keys = s.split('+');
var keys = s.split('-');
var k, i;
for (i in keys) {
k = keys[i];

@ -1,13 +1,13 @@
var normalized_shortcuts = [
'ctrl+shift+m',
'alt+meta+p',
'ctrl-shift-m',
'alt-meta-p',
];
var to_normalize = [
['shift+%', 'shift+5'],
['ShiFT+MeTa+CtRl+AlT+m', 'alt+ctrl+meta+shift+m'],
['shift-%', 'shift-5'],
['ShiFT-MeTa-CtRl-AlT-m', 'alt-ctrl-meta-shift-m'],
];
var unshifted = "` 1 2 3 4 5 6 7 8 9 0 - = q w e r t y u i o p [ ] \\ a s d f g h j k l ; ' z x c v b n m , . /";
@ -33,7 +33,7 @@ casper.notebook_test(function () {
}, item);
this.test.assertEquals(result, item[1], 'Normalize shortcut: '+item[0]);
});
})
});
this.then(function () {
this.each(normalized_shortcuts, function (self, item) {
@ -46,4 +46,4 @@ casper.notebook_test(function () {
});
});
});
});

@ -22,7 +22,7 @@ casper.notebook_test(function () {
var cell = IPython.notebook.get_cell(0);
cell.set_text('a=11; print(a)');
cell.clear_output();
IPython.keyboard.trigger_keydown('shift+enter');
IPython.keyboard.trigger_keydown('shift-enter');
});
this.wait_for_output(0);
@ -41,7 +41,7 @@ casper.notebook_test(function () {
var cell = IPython.notebook.get_cell(0);
cell.set_text('a=12; print(a)');
cell.clear_output();
IPython.keyboard.trigger_keydown('ctrl+enter');
IPython.keyboard.trigger_keydown('ctrl-enter');
});
this.wait_for_output(0);

Loading…
Cancel
Save