##// END OF EJS Templates
Backport PR #8271: Allow to set same mode as existing if load fails....
Min RK -
Show More
@@ -1495,29 +1495,50 b' define(function (require) {'
1495 Notebook.prototype.cell_toggle_line_numbers = function() {
1495 Notebook.prototype.cell_toggle_line_numbers = function() {
1496 this.get_selected_cell().toggle_line_numbers();
1496 this.get_selected_cell().toggle_line_numbers();
1497 };
1497 };
1498
1499
1500 //dispatch codemirror mode to all cells.
1501 Notebook.prototype._dispatch_mode = function(spec, newmode){
1502 this.codemirror_mode = newmode;
1503 codecell.CodeCell.options_default.cm_config.mode = newmode;
1504 this.get_cells().map(function(cell, i) {
1505 if (cell.cell_type === 'code'){
1506 cell.code_mirror.setOption('mode', spec);
1507 // This is currently redundant, because cm_config ends up as
1508 // codemirror's own .options object, but I don't want to
1509 // rely on that.
1510 cell.cm_config.mode = spec;
1511 }
1512 });
1513
1514 };
1515
1516 // roughly try to check mode equality
1517 var _mode_equal = function(mode1, mode2){
1518 return ((mode1||{}).name||mode1)===((mode2||{}).name||mode2);
1519 };
1498
1520
1499 /**
1521 /**
1500 * Set the codemirror mode for all code cells, including the default for
1522 * Set the codemirror mode for all code cells, including the default for
1501 * new code cells.
1523 * new code cells.
1524 * Set the mode to 'null' (no highlighting) if it can't be found.
1502 */
1525 */
1503 Notebook.prototype.set_codemirror_mode = function(newmode){
1526 Notebook.prototype.set_codemirror_mode = function(newmode){
1504 if (newmode === this.codemirror_mode) {
1527 // if mode is the same don't reset,
1528 // to avoid n-time re-highlighting.
1529 if (_mode_equal(newmode, this.codemirror_mode)) {
1505 return;
1530 return;
1506 }
1531 }
1507 this.codemirror_mode = newmode;
1508 codecell.CodeCell.options_default.cm_config.mode = newmode;
1509
1532
1510 var that = this;
1533 var that = this;
1511 utils.requireCodeMirrorMode(newmode, function (spec) {
1534 utils.requireCodeMirrorMode(newmode, function (spec) {
1512 that.get_cells().map(function(cell, i) {
1535 that._dispatch_mode(spec, newmode);
1513 if (cell.cell_type === 'code'){
1536 }, function(){
1514 cell.code_mirror.setOption('mode', spec);
1537 // on error don't dispatch the new mode as re-setting it later will not work.
1515 // This is currently redundant, because cm_config ends up as
1538 // don't either set to null mode if it has been changed in the meantime
1516 // codemirror's own .options object, but I don't want to
1539 if( _mode_equal(newmode, this.codemirror_mode) ){
1517 // rely on that.
1540 that._dispatch_mode('null','null');
1518 cell._options.cm_config.mode = spec;
1541 }
1519 }
1520 });
1521 });
1542 });
1522 };
1543 };
1523
1544
@@ -2102,7 +2123,6 b' define(function (require) {'
2102 * @param {string} notebook_path - A notebook to load
2123 * @param {string} notebook_path - A notebook to load
2103 */
2124 */
2104 Notebook.prototype.load_notebook = function (notebook_path) {
2125 Notebook.prototype.load_notebook = function (notebook_path) {
2105 var that = this;
2106 this.notebook_path = notebook_path;
2126 this.notebook_path = notebook_path;
2107 this.notebook_name = utils.url_path_split(this.notebook_path)[1];
2127 this.notebook_name = utils.url_path_split(this.notebook_path)[1];
2108 this.events.trigger('notebook_loading.Notebook');
2128 this.events.trigger('notebook_loading.Notebook');
General Comments 0
You need to be logged in to leave comments. Login now