Skip to content

Commit

Permalink
Merge pull request #1184 from jcb91/ch
Browse files Browse the repository at this point in the history
[collapsible_headings] patch TextCell.set_text
  • Loading branch information
jcb91 authored Dec 22, 2017
2 parents 1a6b9b6 + c8739d3 commit 7636fcf
Showing 1 changed file with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// if here, the Jupyter namespace hasn't been specified to be loaded.
// This means that we're probably embedded in a page, so we need to make
// our definition with a specific module name
"use strict";
return define('nbextensions/collapsible_headings/main', deps, callback);
})(['jquery', 'require'], function ($, requirejs) {
"use strict";
Expand Down Expand Up @@ -540,20 +541,40 @@
}
return orig_notebook_select.apply(this, arguments);
};
resolve();
}, reject);
}).catch(function on_reject (reason) {
console.warn(log_prefix, 'error patching Notebook.protoype:', reason);
});
}

// we have to patch undelete, as there is no event to bind to. We
// could bind to create.Cell, but that'd be a bit OTT
var orig_notebook_undelete = notebook.Notebook.prototype.undelete;
notebook.Notebook.prototype.undelete = function () {
var ret = orig_notebook_undelete.apply(this, arguments);
update_collapsed_headings();
/**
* Return a promise which resolves when the TextCell class methods have
* been appropriately patched.
*
* Patches TextCell.set_text to update headings.
* This is useful for undelete and copy/paste of cells, which don't fire
* markdown.
*
* @return {Promise}
*/
function patch_TextCell () {
return new Promise(function (resolve, reject) {
requirejs(['notebook/js/textcell'], function on_success (textcell) {
console.debug(log_prefix, 'patching TextCell.protoype');
var orig_set_text = textcell.TextCell.prototype.set_text;
textcell.TextCell.prototype.set_text = function (text) {
var ret = orig_set_text.apply(this, arguments);
if (Jupyter.notebook._fully_loaded) {
update_heading_cell_status(this);
update_collapsed_headings();
}
return ret;
};

resolve();
}, reject);
}).catch(function on_reject (reason) {
console.warn(log_prefix, 'error patching Notebook.protoype:', reason);
console.warn(log_prefix, 'error patching TextCell.protoype:', reason);
});
}

Expand Down Expand Up @@ -1028,9 +1049,9 @@
// apply all promisory things in arbitrary order
.then(patch_actions)
.then(patch_Notebook)
.then(patch_TextCell)
.then(patch_Tooltip)
.then(bind_events)

// finally add user-interaction stuff
.then(function () {
register_new_actions();
Expand Down

0 comments on commit 7636fcf

Please sign in to comment.