##// END OF EJS Templates
Merge pull request #8271 from Carreau/fix-mode-load...
Min RK -
r21207:de7aa5d0 merge
parent child Browse files
Show More
@@ -1514,29 +1514,50 define(function (require) {
1514 Notebook.prototype.cell_toggle_line_numbers = function() {
1514 Notebook.prototype.cell_toggle_line_numbers = function() {
1515 this.get_selected_cell().toggle_line_numbers();
1515 this.get_selected_cell().toggle_line_numbers();
1516 };
1516 };
1517
1518
1519 //dispatch codemirror mode to all cells.
1520 Notebook.prototype._dispatch_mode = function(spec, newmode){
1521 this.codemirror_mode = newmode;
1522 codecell.CodeCell.options_default.cm_config.mode = newmode;
1523 this.get_cells().map(function(cell, i) {
1524 if (cell.cell_type === 'code'){
1525 cell.code_mirror.setOption('mode', spec);
1526 // This is currently redundant, because cm_config ends up as
1527 // codemirror's own .options object, but I don't want to
1528 // rely on that.
1529 cell.cm_config.mode = spec;
1530 }
1531 });
1532
1533 };
1534
1535 // roughly try to check mode equality
1536 var _mode_equal = function(mode1, mode2){
1537 return ((mode1||{}).name||mode1)===((mode2||{}).name||mode2);
1538 };
1517
1539
1518 /**
1540 /**
1519 * Set the codemirror mode for all code cells, including the default for
1541 * Set the codemirror mode for all code cells, including the default for
1520 * new code cells.
1542 * new code cells.
1543 * Set the mode to 'null' (no highlighting) if it can't be found.
1521 */
1544 */
1522 Notebook.prototype.set_codemirror_mode = function(newmode){
1545 Notebook.prototype.set_codemirror_mode = function(newmode){
1523 if (newmode === this.codemirror_mode) {
1546 // if mode is the same don't reset,
1547 // to avoid n-time re-highlighting.
1548 if (_mode_equal(newmode, this.codemirror_mode)) {
1524 return;
1549 return;
1525 }
1550 }
1526 this.codemirror_mode = newmode;
1527 codecell.CodeCell.options_default.cm_config.mode = newmode;
1528
1551
1529 var that = this;
1552 var that = this;
1530 utils.requireCodeMirrorMode(newmode, function (spec) {
1553 utils.requireCodeMirrorMode(newmode, function (spec) {
1531 that.get_cells().map(function(cell, i) {
1554 that._dispatch_mode(spec, newmode);
1532 if (cell.cell_type === 'code'){
1555 }, function(){
1533 cell.code_mirror.setOption('mode', spec);
1556 // on error don't dispatch the new mode as re-setting it later will not work.
1534 // This is currently redundant, because cm_config ends up as
1557 // don't either set to null mode if it has been changed in the meantime
1535 // codemirror's own .options object, but I don't want to
1558 if( _mode_equal(newmode, this.codemirror_mode) ){
1536 // rely on that.
1559 that._dispatch_mode('null','null');
1537 cell.cm_config.mode = spec;
1560 }
1538 }
1539 });
1540 });
1561 });
1541 };
1562 };
1542
1563
@@ -2121,7 +2142,6 define(function (require) {
2121 * @param {string} notebook_path - A notebook to load
2142 * @param {string} notebook_path - A notebook to load
2122 */
2143 */
2123 Notebook.prototype.load_notebook = function (notebook_path) {
2144 Notebook.prototype.load_notebook = function (notebook_path) {
2124 var that = this;
2125 this.notebook_path = notebook_path;
2145 this.notebook_path = notebook_path;
2126 this.notebook_name = utils.url_path_split(this.notebook_path)[1];
2146 this.notebook_name = utils.url_path_split(this.notebook_path)[1];
2127 this.events.trigger('notebook_loading.Notebook');
2147 this.events.trigger('notebook_loading.Notebook');
General Comments 0
You need to be logged in to leave comments. Login now