From 206d35a89e426cabe290ff0058e3a4e5babf4725 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Tue, 18 Feb 2014 12:45:22 -0800 Subject: [PATCH] DEBUG Added lots of log calls and a couple small 'fixes' (attempts) --- IPython/html/static/notebook/js/cell.js | 30 ++++++++++++------- .../static/notebook/js/keyboardmanager.js | 7 +++++ IPython/html/static/notebook/js/notebook.js | 11 ++++++- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/IPython/html/static/notebook/js/cell.js b/IPython/html/static/notebook/js/cell.js index decd9473e..d3def63d7 100644 --- a/IPython/html/static/notebook/js/cell.js +++ b/IPython/html/static/notebook/js/cell.js @@ -147,23 +147,31 @@ var IPython = (function (IPython) { } if (this.code_mirror) { this.code_mirror.on('focus', function(cm, change) { - $([IPython.events]).trigger('edit_mode.Cell', {cell: that}); + 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 (! (isf('div#tooltip') || isf('div.completions'))) { + if (that.mode === 'edit') { + $([IPython.events]).trigger('command_mode.Cell', {cell: that}); + } } - if (trigger) { - $([IPython.events]).trigger('command_mode.Cell', {cell: that}); - } - }, 1); - } + } + }, that), 1); }); } }; diff --git a/IPython/html/static/notebook/js/keyboardmanager.js b/IPython/html/static/notebook/js/keyboardmanager.js index b54a6604f..94068cd6a 100644 --- a/IPython/html/static/notebook/js/keyboardmanager.js +++ b/IPython/html/static/notebook/js/keyboardmanager.js @@ -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(); } }); diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index e4c45c794..a853081c7 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -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);