|
|
|
|
@ -74,7 +74,7 @@ var IPython = (function (IPython) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var cm_overwrite_options = {
|
|
|
|
|
onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
|
|
|
|
|
onKeyEvent: $.proxy(this.handle_keyevent,this)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
options = this.mergeopt(CodeCell, options, {cm_config:cm_overwrite_options});
|
|
|
|
|
@ -149,6 +149,17 @@ var IPython = (function (IPython) {
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CodeCell.prototype.handle_keyevent = function (editor, event) {
|
|
|
|
|
|
|
|
|
|
console.log('CM', this.mode, event.which, event.type)
|
|
|
|
|
|
|
|
|
|
if (this.mode === 'command') {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (this.mode === 'edit') {
|
|
|
|
|
return this.handle_codemirror_keyevent(editor, event);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This method gets called in CodeMirror's onKeyDown/onKeyPress
|
|
|
|
|
* handlers and is used to provide custom key handling. Its return
|
|
|
|
|
@ -157,61 +168,55 @@ var IPython = (function (IPython) {
|
|
|
|
|
* @method handle_codemirror_keyevent
|
|
|
|
|
*/
|
|
|
|
|
CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) {
|
|
|
|
|
|
|
|
|
|
var that = this;
|
|
|
|
|
// whatever key is pressed, first, cancel the tooltip request before
|
|
|
|
|
// they are sent, and remove tooltip if any, except for tab again
|
|
|
|
|
if (event.type === 'keydown' && event.which != key.TAB ) {
|
|
|
|
|
IPython.tooltip.remove_and_cancel_tooltip();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.mode === 'command') {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (this.mode === 'edit') {
|
|
|
|
|
// whatever key is pressed, first, cancel the tooltip request before
|
|
|
|
|
// they are sent, and remove tooltip if any, except for tab again
|
|
|
|
|
if (event.type === 'keydown' && event.which != key.TAB ) {
|
|
|
|
|
IPython.tooltip.remove_and_cancel_tooltip();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var cur = editor.getCursor();
|
|
|
|
|
if (event.keyCode === key.ENTER){
|
|
|
|
|
this.auto_highlight();
|
|
|
|
|
}
|
|
|
|
|
var cur = editor.getCursor();
|
|
|
|
|
if (event.keyCode === key.ENTER){
|
|
|
|
|
this.auto_highlight();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.keyCode === key.ENTER && (event.shiftKey || event.ctrlKey || event.altKey)) {
|
|
|
|
|
// Always ignore shift-enter in CodeMirror as we handle it.
|
|
|
|
|
if (event.keyCode === key.ENTER && (event.shiftKey || event.ctrlKey)) {
|
|
|
|
|
// Always ignore shift-enter in CodeMirror as we handle it.
|
|
|
|
|
return true;
|
|
|
|
|
} else if (event.which === 40 && event.type === 'keypress' && IPython.tooltip.time_before_tooltip >= 0) {
|
|
|
|
|
// triger on keypress (!) otherwise inconsistent event.which depending on plateform
|
|
|
|
|
// browser and keyboard layout !
|
|
|
|
|
// Pressing '(' , request tooltip, don't forget to reappend it
|
|
|
|
|
// The second argument says to hide the tooltip if the docstring
|
|
|
|
|
// is actually empty
|
|
|
|
|
IPython.tooltip.pending(that, true);
|
|
|
|
|
} else if (event.which === key.UPARROW && event.type === 'keydown') {
|
|
|
|
|
// 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()) {
|
|
|
|
|
event.stop();
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
} else if (event.which === 40 && event.type === 'keypress' && IPython.tooltip.time_before_tooltip >= 0) {
|
|
|
|
|
// triger on keypress (!) otherwise inconsistent event.which depending on plateform
|
|
|
|
|
// browser and keyboard layout !
|
|
|
|
|
// Pressing '(' , request tooltip, don't forget to reappend it
|
|
|
|
|
// The second argument says to hide the tooltip if the docstring
|
|
|
|
|
// is actually empty
|
|
|
|
|
IPython.tooltip.pending(that, true);
|
|
|
|
|
} else if (event.which === key.UPARROW && event.type === 'keydown') {
|
|
|
|
|
// 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()) {
|
|
|
|
|
event.stop();
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
} else if (event.which === key.ESC) {
|
|
|
|
|
IPython.tooltip.remove_and_cancel_tooltip(true);
|
|
|
|
|
}
|
|
|
|
|
} else if (event.which === key.ESC) {
|
|
|
|
|
return IPython.tooltip.remove_and_cancel_tooltip(true);
|
|
|
|
|
} else if (event.which === key.DOWNARROW && event.type === 'keydown') {
|
|
|
|
|
// 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()) {
|
|
|
|
|
event.stop();
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (event.which === key.DOWNARROW && event.type === 'keydown') {
|
|
|
|
|
// 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()) {
|
|
|
|
|
event.stop();
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
} else if (event.keyCode === key.TAB && event.type == 'keydown' && event.shiftKey) {
|
|
|
|
|
if (editor.somethingSelected()){
|
|
|
|
|
var anchor = editor.getCursor("anchor");
|
|
|
|
|
var head = editor.getCursor("head");
|
|
|
|
|
if( anchor.line != head.line){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (event.keyCode === key.TAB && event.type == 'keydown' && event.shiftKey) {
|
|
|
|
|
if (editor.somethingSelected()){
|
|
|
|
|
var anchor = editor.getCursor("anchor");
|
|
|
|
|
var head = editor.getCursor("head");
|
|
|
|
|
if( anchor.line != head.line){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
IPython.tooltip.request(that);
|
|
|
|
|
@ -229,16 +234,18 @@ var IPython = (function (IPython) {
|
|
|
|
|
// is empty. In this case, let CodeMirror handle indentation.
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
// keypress/keyup also trigger on TAB press, and we don't want to
|
|
|
|
|
// use those to disable tab completion.
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
event.stop();
|
|
|
|
|
this.completer.startCompletion();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// keypress/keyup also trigger on TAB press, and we don't want to
|
|
|
|
|
// use those to disable tab completion.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Kernel related calls.
|
|
|
|
|
|
|
|
|
|
CodeCell.prototype.set_kernel = function (kernel) {
|
|
|
|
|
|