Added lots of log calls and a couple small 'fixes' (attempts)
This commit is contained in:
Jonathan Frederic 2014-02-18 12:45:22 -08:00
parent 7913305312
commit 206d35a89e
3 changed files with 36 additions and 12 deletions

View File

@ -147,23 +147,31 @@ var IPython = (function (IPython) {
}
if (this.code_mirror) {
this.code_mirror.on('focus', function(cm, change) {
console.log('cell focused');
if (that._continue_blur) {
that._continue_blur = false;
} else {
if (that.mode === 'command') {
$([IPython.events]).trigger('edit_mode.Cell', {cell: that});
}
}
});
}
if (this.code_mirror) {
this.code_mirror.on('blur', function(cm, change) {
if (that.mode === 'edit') {
setTimeout(function () {
console.log('cell blur');
that._continue_blur = true;
setTimeout($.proxy(function () {
if (that._continue_blur) {
console.log('cell blur> edit true> callback');
var isf = IPython.utils.is_focused;
var trigger = true;
if (isf('div#tooltip') || isf('div.completions')) {
trigger = false;
}
if (trigger) {
if (! (isf('div#tooltip') || isf('div.completions'))) {
if (that.mode === 'edit') {
$([IPython.events]).trigger('command_mode.Cell', {cell: that});
}
}, 1);
}
}
}, that), 1);
});
}
};

View File

@ -725,29 +725,35 @@ var IPython = (function (IPython) {
};
KeyboardManager.prototype.edit_mode = function () {
console.log('kb edit');
this.last_mode = this.mode;
this.mode = 'edit';
};
KeyboardManager.prototype.command_mode = function () {
console.log('kb command');
this.last_mode = this.mode;
this.mode = 'command';
};
KeyboardManager.prototype.enable = function () {
console.log('kb enable');
this.enabled = true;
};
KeyboardManager.prototype.disable = function () {
console.log('kb disable');
this.enabled = false;
};
KeyboardManager.prototype.register_events = function (e) {
var that = this;
e.on('focusin', function () {
console.log('kb focus in');
that.disable();
});
e.on('focusout', function () {
console.log('kb focus out');
that.enable();
});
// There are times (raw_input) where we remove the element from the DOM before
@ -755,6 +761,7 @@ var IPython = (function (IPython) {
// which gets triggered upon removal, iff it is focused at the time.
e.on('remove', function () {
if (document.activeElement === e[0]) {
console.log('kb remove');
that.enable();
}
});

View File

@ -116,12 +116,18 @@ var IPython = (function (IPython) {
});
$([IPython.events]).on('edit_mode.Cell', function (event, data) {
console.log('edit mode cell');
var index = that.find_cell_index(data.cell);
that.select(index);
that.edit_mode();
});
$([IPython.events]).on('command_mode.Cell', function (event, data) {
console.log('command mode cell');
// In Firefox the focus event is called before the blur event. In
// other words, two cells elements may be focused at any given time.
// Here we verify that no cells are currently in edit mode before
// putting the entire notebook in command mode.
that.command_mode();
});
@ -459,7 +465,6 @@ var IPython = (function (IPython) {
if (this.is_valid_cell_index(index)) {
var sindex = this.get_selected_index();
if (sindex !== null && index !== sindex) {
this.command_mode();
this.get_cell(sindex).unselect();
}
var cell = this.get_cell(index);
@ -515,6 +520,7 @@ var IPython = (function (IPython) {
};
Notebook.prototype.command_mode = function () {
console.log('cell.command_mode');
if (this.mode !== 'command') {
$([IPython.events]).trigger('command_mode.Notebook');
var index = this.get_edit_index();
@ -528,6 +534,7 @@ var IPython = (function (IPython) {
};
Notebook.prototype.edit_mode = function () {
console.log('cell.edit_mode');
if (this.mode !== 'edit') {
$([IPython.events]).trigger('edit_mode.Notebook');
var cell = this.get_selected_cell();
@ -1402,6 +1409,7 @@ var IPython = (function (IPython) {
var cell = this.get_selected_cell();
var cell_index = this.find_cell_index(cell);
console.log('execute cell command_mode');
cell.execute();
this.command_mode();
cell.focus_cell();
@ -1923,6 +1931,7 @@ var IPython = (function (IPython) {
*/
Notebook.prototype.load_notebook_success = function (data, status, xhr) {
this.fromJSON(data);
console.log('load notebook success');
if (this.ncells() === 0) {
this.insert_cell_below('code');
this.select(0);