Show More
@@ -73,22 +73,7 b' function($,' | |||||
73 | // Setting the file's initial value creates a history entry, |
|
73 | // Setting the file's initial value creates a history entry, | |
74 | // which we don't want. |
|
74 | // which we don't want. | |
75 | cm.clearHistory(); |
|
75 | cm.clearHistory(); | |
76 |
|
76 | that._set_mode_for_model(model); | ||
77 | // Find and load the highlighting mode, |
|
|||
78 | // first by mime-type, then by file extension |
|
|||
79 | var modeinfo = CodeMirror.findModeByMIME(model.mimetype); |
|
|||
80 | if (modeinfo.mode === "null") { |
|
|||
81 | // find by mime failed, use find by ext |
|
|||
82 | var ext_idx = model.name.lastIndexOf('.'); |
|
|||
83 |
|
||||
84 | if (ext_idx > 0) { |
|
|||
85 | // CodeMirror.findModeByExtension wants extension without '.' |
|
|||
86 | modeinfo = CodeMirror.findModeByExtension(model.name.slice(ext_idx + 1)); |
|
|||
87 | } |
|
|||
88 | } |
|
|||
89 | if (modeinfo) { |
|
|||
90 | that.set_codemirror_mode(modeinfo); |
|
|||
91 | } |
|
|||
92 | that.save_enabled = true; |
|
77 | that.save_enabled = true; | |
93 | that.generation = cm.changeGeneration(); |
|
78 | that.generation = cm.changeGeneration(); | |
94 | that.events.trigger("file_loaded.Editor", model); |
|
79 | that.events.trigger("file_loaded.Editor", model); | |
@@ -100,6 +85,26 b' function($,' | |||||
100 | } |
|
85 | } | |
101 | ); |
|
86 | ); | |
102 | }; |
|
87 | }; | |
|
88 | ||||
|
89 | Editor.prototype._set_mode_for_model = function (model) { | |||
|
90 | /** Set the CodeMirror mode based on the file model */ | |||
|
91 | ||||
|
92 | // Find and load the highlighting mode, | |||
|
93 | // first by mime-type, then by file extension | |||
|
94 | var modeinfo = CodeMirror.findModeByMIME(model.mimetype); | |||
|
95 | if (modeinfo.mode === "null") { | |||
|
96 | // find by mime failed, use find by ext | |||
|
97 | var ext_idx = model.name.lastIndexOf('.'); | |||
|
98 | ||||
|
99 | if (ext_idx > 0) { | |||
|
100 | // CodeMirror.findModeByExtension wants extension without '.' | |||
|
101 | modeinfo = CodeMirror.findModeByExtension(model.name.slice(ext_idx + 1)); | |||
|
102 | } | |||
|
103 | } | |||
|
104 | if (modeinfo) { | |||
|
105 | this.set_codemirror_mode(modeinfo); | |||
|
106 | } | |||
|
107 | }; | |||
103 |
|
108 | |||
104 | Editor.prototype.set_codemirror_mode = function (modeinfo) { |
|
109 | Editor.prototype.set_codemirror_mode = function (modeinfo) { | |
105 | /** set the codemirror mode from a modeinfo struct */ |
|
110 | /** set the codemirror mode from a modeinfo struct */ | |
@@ -120,9 +125,10 b' function($,' | |||||
120 | var parent = utils.url_path_split(this.file_path)[0]; |
|
125 | var parent = utils.url_path_split(this.file_path)[0]; | |
121 | var new_path = utils.url_path_join(parent, new_name); |
|
126 | var new_path = utils.url_path_join(parent, new_name); | |
122 | return this.contents.rename(this.file_path, new_path).then( |
|
127 | return this.contents.rename(this.file_path, new_path).then( | |
123 |
function ( |
|
128 | function (model) { | |
124 |
that.file_path = |
|
129 | that.file_path = model.path; | |
125 |
that.events.trigger('file_renamed.Editor', |
|
130 | that.events.trigger('file_renamed.Editor', model); | |
|
131 | that._set_mode_for_model(model); | |||
126 | } |
|
132 | } | |
127 | ); |
|
133 | ); | |
128 | }; |
|
134 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now