Show More
@@ -1515,29 +1515,50 define(function (require) { | |||
|
1515 | 1515 | this.get_selected_cell().toggle_line_numbers(); |
|
1516 | 1516 | }; |
|
1517 | 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 | }; | |
|
1539 | ||
|
1518 | 1540 | /** |
|
1519 | 1541 | * Set the codemirror mode for all code cells, including the default for |
|
1520 | 1542 | * new code cells. |
|
1543 | * Set the mode to 'null' (no highlighting) if it can't be found. | |
|
1521 | 1544 | */ |
|
1522 | 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 | 1549 | return; |
|
1525 | 1550 | } |
|
1526 | this.codemirror_mode = newmode; | |
|
1527 | codecell.CodeCell.options_default.cm_config.mode = newmode; | |
|
1528 | 1551 | |
|
1529 | 1552 | var that = this; |
|
1530 | 1553 | utils.requireCodeMirrorMode(newmode, function (spec) { |
|
1531 | that.get_cells().map(function(cell, i) { | |
|
1532 | if (cell.cell_type === 'code'){ | |
|
1533 | cell.code_mirror.setOption('mode', spec); | |
|
1534 | // This is currently redundant, because cm_config ends up as | |
|
1535 | // codemirror's own .options object, but I don't want to | |
|
1536 | // rely on that. | |
|
1537 | cell.cm_config.mode = spec; | |
|
1554 | that._dispatch_mode(spec, newmode); | |
|
1555 | }, function(){ | |
|
1556 | // on error don't dispatch the new mode as re-setting it later will not work. | |
|
1557 | // don't either set to null mode if it has been changed in the meantime | |
|
1558 | if( _mode_equal(newmode, this.codemirror_mode) ){ | |
|
1559 | that._dispatch_mode('null','null'); | |
|
1538 | 1560 |
|
|
1539 | 1561 |
|
|
1540 | }); | |
|
1541 | 1562 | }; |
|
1542 | 1563 | |
|
1543 | 1564 | // Session related things |
@@ -2121,7 +2142,6 define(function (require) { | |||
|
2121 | 2142 | * @param {string} notebook_path - A notebook to load |
|
2122 | 2143 | */ |
|
2123 | 2144 | Notebook.prototype.load_notebook = function (notebook_path) { |
|
2124 | var that = this; | |
|
2125 | 2145 | this.notebook_path = notebook_path; |
|
2126 | 2146 | this.notebook_name = utils.url_path_split(this.notebook_path)[1]; |
|
2127 | 2147 | this.events.trigger('notebook_loading.Notebook'); |
General Comments 0
You need to be logged in to leave comments.
Login now