add a keycodes structure to utils

this structure (IPython.utils.keycodes)
    add some common keycodes like tab...etc

    and start modifying codecell.js to use it for better readability
Matthias BUSSONNIER 14 years ago committed by Brian Granger
parent 472fe4c19e
commit fa6b8974ea

@ -13,6 +13,7 @@ var IPython = (function (IPython) {
"use strict";
var utils = IPython.utils;
var key = IPython.utils.keycodes;
var CodeCell = function (notebook) {
this.code_mirror = null;
@ -101,7 +102,7 @@ var IPython = (function (IPython) {
var cursor = editor.getCursor();
var pre_cursor = editor.getRange({line:cursor.line,ch:0},cursor).trim()+'(';
that.request_tooltip_after_time(pre_cursor,tooltip_wait_time);
} else if (event.which === 38) {
} else if (event.which === key.upArrow) {
// If we are not at the top, let CM handle the up arrow and
// prevent the global keydown handler from handling it.
if (!that.at_top()) {
@ -110,7 +111,7 @@ var IPython = (function (IPython) {
} else {
return true;
};
} else if (event.which === 40) {
} else if (event.which === key.downArrow) {
// If we are not at the bottom, let CM handle the down arrow and
// prevent the global keydown handler from handling it.
if (!that.at_bottom()) {
@ -119,7 +120,7 @@ var IPython = (function (IPython) {
} else {
return true;
};
} else if (event.keyCode === 9 && event.type == 'keydown') {
} else if (event.keyCode === key.tab && event.type == 'keydown') {
// Tab completion.
var cur = editor.getCursor();
//Do not trim here because of tooltip
@ -139,7 +140,7 @@ var IPython = (function (IPython) {
this.completer.startCompletion();
return true;
};
} else if (event.keyCode === 8 && event.type == 'keydown') {
} else if (event.keyCode === key.backspace && event.type == 'keydown') {
// If backspace and the line ends with 4 spaces, remove them.
var cur = editor.getCursor();
var line = editor.getLine(cur.line);
@ -157,7 +158,7 @@ var IPython = (function (IPython) {
} else {
// keypress/keyup also trigger on TAB press, and we don't want to
// use those to disable tab completion.
if (this.is_completing && event.keyCode !== 9) {
if (this.is_completing && event.keyCode !== key.tab) {
var ed_cur = editor.getCursor();
var cc_cur = this.completion_cursor;
if (ed_cur.line !== cc_cur.line || ed_cur.ch !== cc_cur.ch) {

@ -91,11 +91,29 @@ IPython.utils = (function (IPython) {
}
};
// some keycodes that seem to be platform/browser independant
var keycodes ={
backspace: 8,
tab : 9,
enter : 13,
shift : 16,
esc : 27,
space : 32,
pgUp : 33,
pgDown : 34,
leftArrow: 37,
left : 37,
upArrow : 38,
rightArrow:39,
right : 39,
downArrow: 40,
};
return {
uuid : uuid,
fixConsole : fixConsole,
grow : grow
keycodes : keycodes,
grow : grow,
};
}(IPython));

Loading…
Cancel
Save