|
2 | 2 | // if here, the Jupyter namespace hasn't been specified to be loaded.
|
3 | 3 | // This means that we're probably embedded in a page, so we need to make
|
4 | 4 | // our definition with a specific module name
|
| 5 | + "use strict"; |
5 | 6 | return define('nbextensions/collapsible_headings/main', deps, callback);
|
6 | 7 | })(['jquery', 'require'], function ($, requirejs) {
|
7 | 8 | "use strict";
|
|
540 | 541 | }
|
541 | 542 | return orig_notebook_select.apply(this, arguments);
|
542 | 543 | };
|
| 544 | + resolve(); |
| 545 | + }, reject); |
| 546 | + }).catch(function on_reject (reason) { |
| 547 | + console.warn(log_prefix, 'error patching Notebook.protoype:', reason); |
| 548 | + }); |
| 549 | + } |
543 | 550 |
|
544 |
| - // we have to patch undelete, as there is no event to bind to. We |
545 |
| - // could bind to create.Cell, but that'd be a bit OTT |
546 |
| - var orig_notebook_undelete = notebook.Notebook.prototype.undelete; |
547 |
| - notebook.Notebook.prototype.undelete = function () { |
548 |
| - var ret = orig_notebook_undelete.apply(this, arguments); |
549 |
| - update_collapsed_headings(); |
| 551 | + /** |
| 552 | + * Return a promise which resolves when the TextCell class methods have |
| 553 | + * been appropriately patched. |
| 554 | + * |
| 555 | + * Patches TextCell.set_text to update headings. |
| 556 | + * This is useful for undelete and copy/paste of cells, which don't fire |
| 557 | + * markdown. |
| 558 | + * |
| 559 | + * @return {Promise} |
| 560 | + */ |
| 561 | + function patch_TextCell () { |
| 562 | + return new Promise(function (resolve, reject) { |
| 563 | + requirejs(['notebook/js/textcell'], function on_success (textcell) { |
| 564 | + console.debug(log_prefix, 'patching TextCell.protoype'); |
| 565 | + var orig_set_text = textcell.TextCell.prototype.set_text; |
| 566 | + textcell.TextCell.prototype.set_text = function (text) { |
| 567 | + var ret = orig_set_text.apply(this, arguments); |
| 568 | + if (Jupyter.notebook._fully_loaded) { |
| 569 | + update_heading_cell_status(this); |
| 570 | + update_collapsed_headings(); |
| 571 | + } |
550 | 572 | return ret;
|
551 | 573 | };
|
552 |
| - |
553 | 574 | resolve();
|
554 | 575 | }, reject);
|
555 | 576 | }).catch(function on_reject (reason) {
|
556 |
| - console.warn(log_prefix, 'error patching Notebook.protoype:', reason); |
| 577 | + console.warn(log_prefix, 'error patching TextCell.protoype:', reason); |
557 | 578 | });
|
558 | 579 | }
|
559 | 580 |
|
|
1028 | 1049 | // apply all promisory things in arbitrary order
|
1029 | 1050 | .then(patch_actions)
|
1030 | 1051 | .then(patch_Notebook)
|
| 1052 | + .then(patch_TextCell) |
1031 | 1053 | .then(patch_Tooltip)
|
1032 | 1054 | .then(bind_events)
|
1033 |
| - |
1034 | 1055 | // finally add user-interaction stuff
|
1035 | 1056 | .then(function () {
|
1036 | 1057 | register_new_actions();
|
|
0 commit comments