Skip to content

Commit

Permalink
Merge pull request #7361 from quantopian/fix-extension-rename
Browse files Browse the repository at this point in the history
BUG: Fix broken codemirror highlighting on file rename.
  • Loading branch information
minrk committed Jan 3, 2015
2 parents 22a44b8 + ed5bf68 commit a6ac0e7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions IPython/html/static/edit/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,19 @@ function($,

Editor.prototype._set_mode_for_model = function (model) {
/** Set the CodeMirror mode based on the file model */

// Find and load the highlighting mode,
// first by mime-type, then by file extension
var modeinfo = CodeMirror.findModeByMIME(model.mimetype);
if (modeinfo.mode === "null") {

var modeinfo;
// mimetype is unset on file rename
if (model.mimetype) {
modeinfo = CodeMirror.findModeByMIME(model.mimetype);
}
if (!modeinfo || modeinfo.mode === "null") {
// find by mime failed, use find by ext
var ext_idx = model.name.lastIndexOf('.');

if (ext_idx > 0) {
// CodeMirror.findModeByExtension wants extension without '.'
modeinfo = CodeMirror.findModeByExtension(model.name.slice(ext_idx + 1));
Expand All @@ -114,7 +119,7 @@ function($,
this.set_codemirror_mode(modeinfo);
}
};

Editor.prototype.set_codemirror_mode = function (modeinfo) {
/** set the codemirror mode from a modeinfo struct */
var that = this;
Expand Down

0 comments on commit a6ac0e7

Please sign in to comment.