Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Unified Diff: third_party/WebKit/Source/devtools/front_end/text_editor/CodeMirrorTextEditor.js

Issue 2498783002: DevTools: [Sources] Improve editor load time by optimizing setMimeType (Closed)
Patch Set: Remove unneeded if Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/text_editor/CodeMirrorTextEditor.js
diff --git a/third_party/WebKit/Source/devtools/front_end/text_editor/CodeMirrorTextEditor.js b/third_party/WebKit/Source/devtools/front_end/text_editor/CodeMirrorTextEditor.js
index 5e1c09dabb21a8da2d9faff18e7d26b7359e010a..fdcc9c507c6d7672ba90f4e9da86c607dce2c3a0 100644
--- a/third_party/WebKit/Source/devtools/front_end/text_editor/CodeMirrorTextEditor.js
+++ b/third_party/WebKit/Source/devtools/front_end/text_editor/CodeMirrorTextEditor.js
@@ -164,6 +164,7 @@ TextEditor.CodeMirrorTextEditor = class extends UI.VBox {
this._needsRefresh = true;
+ this._mimeType = '';
if (options.mimeType)
this.setMimeType(options.mimeType);
if (options.autoHeight)
@@ -264,9 +265,9 @@ TextEditor.CodeMirrorTextEditor = class extends UI.VBox {
/**
* @param {string} mimeType
- * @return {!Promise}
+ * @param {function()} callback
*/
- static _loadMimeTypeModes(mimeType) {
+ static _loadMimeTypeModes(mimeType, callback) {
lushnikov 2016/11/16 05:23:35 let's rather split this into two functions. It wou
einbinder 2016/11/16 23:17:54 Done.
var installed = TextEditor.CodeMirrorTextEditor._loadedMimeModeExtensions;
var nameToExtension = new Map();
@@ -292,7 +293,12 @@ TextEditor.CodeMirrorTextEditor = class extends UI.VBox {
var promises = [];
for (var extension of modesToLoad)
promises.push(extension.instance().then(installMode.bind(null, extension)));
- return Promise.all(promises);
+
+ // If we can, run the callback right away to avoid highlighting twice.
+ if (!promises.length)
+ callback();
+ else
+ Promise.all(promises).then(callback);
/**
* @param {!Runtime.Extension} extension
@@ -609,15 +615,36 @@ TextEditor.CodeMirrorTextEditor = class extends UI.VBox {
/**
* @param {string} mimeType
- * @return {!Promise}
*/
setMimeType(mimeType) {
- if (this._hasLongLines())
- this._enableLongLinesMode();
- else
- this._disableLongLinesMode();
- return TextEditor.CodeMirrorTextEditor._loadMimeTypeModes(mimeType).then(
- () => this._codeMirror.setOption('mode', mimeType));
+ this._mimeType = mimeType;
+ TextEditor.CodeMirrorTextEditor._loadMimeTypeModes(mimeType, setMode.bind(this));
+
+ /**
+ * @this {TextEditor.CodeMirrorTextEditor}
+ */
+ function setMode() {
+ var rewrittenMimeType = this.rewriteMimeType(mimeType);
+ if (this._codeMirror.options.mode !== rewrittenMimeType)
+ this._codeMirror.setOption('mode', rewrittenMimeType);
+ }
+ }
+
+ /**
+ * @protected
+ * @param {string} mimeType
+ */
+ rewriteMimeType(mimeType) {
+ // Overridden in SourcesTextEditor
+ return mimeType;
+ }
+
+ /**
+ * @protected
+ * @return {string}
+ */
+ mimeType() {
+ return this._mimeType;
}
/**
@@ -1077,6 +1104,11 @@ TextEditor.CodeMirrorTextEditor = class extends UI.VBox {
this._shouldClearHistory = false;
}
this._detectLineSeparator(text);
+
+ if (this._hasLongLines())
+ this._enableLongLinesMode();
+ else
+ this._disableLongLinesMode();
}
/**

Powered by Google App Engine
This is Rietveld 408576698