diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js
index 8dabfc9f4..11c9a1d4e 100644
--- a/IPython/html/static/notebook/js/notebook.js
+++ b/IPython/html/static/notebook/js/notebook.js
@@ -300,6 +300,24 @@ var IPython = (function (IPython) {
return result;
};
+ /**
+ * Try to get a particular cell by msg_id.
+ *
+ * @method get_msg_cell
+ * @param {String} msg_id A message UUID
+ * @return {Cell} Cell or null if no cell was found.
+ */
+ Notebook.prototype.get_msg_cell = function (msg_id) {
+ var cells = this.get_cells();
+ for (var cell_index in cells) {
+ if (cells[cell_index].last_msg_id == msg_id) {
+ var cell = this.get_cell(cell_index)
+ return cell;
+ }
+ }
+ return null;
+ };
+
/**
* Count the cells in this notebook.
*
diff --git a/IPython/html/static/notebook/js/widget.js b/IPython/html/static/notebook/js/widget.js
index 4a2ab181a..334892971 100644
--- a/IPython/html/static/notebook/js/widget.js
+++ b/IPython/html/static/notebook/js/widget.js
@@ -298,25 +298,30 @@ define(["components/underscore/underscore-min",
// output_area is an instance of Ipython.OutputArea
_get_output_area: function (msg_id) {
- // First, guess cell.execute triggered
- var cells = IPython.notebook.get_cells();
- for (var cell_index in cells) {
- if (cells[cell_index].last_msg_id == msg_id) {
- var cell = IPython.notebook.get_cell(cell_index)
- return cell.output_area;
- }
+ // First, check to see if the msg was triggered by cell execution.
+ var cell = IPython.notebook.get_msg_cell();
+ if (cell != null) {
+ return cell.output_area;
}
- // Second, guess widget triggered
- var callbacks = this.comm_manager.kernel.get_callbacks_for_msg(msg_id)
- if (callbacks != undefined && callbacks.iopub != undefined && callbacks.iopub.get_output_area != undefined) {
+ // Second, check to see if a get_output_area callback was defined
+ // for the message. get_output_area callbacks are registered for
+ // widget messages, so this block is actually checking to see if the
+ // message was triggered by a widget.
+ var kernel = this.comm_manager.kernel;
+ var callbacks = kernel.get_callbacks_for_msg(msg_id);
+ if (callbacks != undefined &&
+ callbacks.iopub != undefined &&
+ callbacks.iopub.get_output_area != undefined) {
+
var output_area = callbacks.iopub.get_output_area();
if (output_area != null) {
return output_area;
}
}
- // Not triggered by a widget or a cell
+ // Not triggered by a cell or widget (no get_output_area callback
+ // exists).
return null;
},