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

Unified Diff: Source/devtools/front_end/DOMSyntaxHighlighter.js

Issue 22638008: DevTools: Use CodeMirror modes instead of highlight tokenizers (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: address comments Created 7 years, 4 months 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
« no previous file with comments | « Source/devtools/front_end/CodeMirrorUtils.js ('k') | Source/devtools/front_end/ScriptFormatterWorker.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/DOMSyntaxHighlighter.js
diff --git a/Source/devtools/front_end/DOMSyntaxHighlighter.js b/Source/devtools/front_end/DOMSyntaxHighlighter.js
index 4ae97ebadcb8801c0f427929a1ad674301d0d2d2..ed5af04ef5bba91e85f54fc7cbd4a7ed1d73f00a 100644
--- a/Source/devtools/front_end/DOMSyntaxHighlighter.js
+++ b/Source/devtools/front_end/DOMSyntaxHighlighter.js
@@ -33,7 +33,8 @@
*/
WebInspector.DOMSyntaxHighlighter = function(mimeType, stripExtraWhitespace)
{
- this._tokenizer = WebInspector.SourceTokenizer.Registry.getInstance().getTokenizer(mimeType);
+ loadScript("CodeMirrorTextEditor.js");
+ this._mimeType = mimeType;
this._stripExtraWhitespace = stripExtraWhitespace;
}
@@ -41,7 +42,7 @@ WebInspector.DOMSyntaxHighlighter.prototype = {
createSpan: function(content, className)
{
var span = document.createElement("span");
- span.className = "webkit-" + className;
+ span.className = "cm-" + className;
if (this._stripExtraWhitespace && className !== "whitespace")
content = content.replace(/^[\n\r]*/, "").replace(/\s*$/, "");
span.appendChild(document.createTextNode(content));
@@ -50,36 +51,31 @@ WebInspector.DOMSyntaxHighlighter.prototype = {
syntaxHighlightNode: function(node)
{
- this._tokenizer.condition = this._tokenizer.createInitialCondition();
var lines = node.textContent.split("\n");
node.removeChildren();
+ var tokenize = WebInspector.CodeMirrorUtils.createTokenizer(this._mimeType);
for (var i = lines[0].length ? 0 : 1; i < lines.length; ++i) {
var line = lines[i];
var plainTextStart = 0;
- this._tokenizer.line = line;
- var column = 0;
- do {
- var newColumn = this._tokenizer.nextToken(column);
- var tokenType = this._tokenizer.tokenType;
+ function processToken(token, tokenType, column, newColumn)
+ {
if (tokenType) {
if (column > plainTextStart) {
var plainText = line.substring(plainTextStart, column);
node.appendChild(document.createTextNode(plainText));
}
- var token = line.substring(column, newColumn);
node.appendChild(this.createSpan(token, tokenType));
plainTextStart = newColumn;
}
- column = newColumn;
- } while (column < line.length)
-
- if (plainTextStart < line.length) {
- var plainText = line.substring(plainTextStart, line.length);
- node.appendChild(document.createTextNode(plainText));
- }
- if (i < lines.length - 1)
- node.appendChild(document.createElement("br"));
+ }
+ tokenize(line, processToken.bind(this));
+ if (plainTextStart < line.length) {
+ var plainText = line.substring(plainTextStart, line.length);
+ node.appendChild(document.createTextNode(plainText));
+ }
+ if (i < lines.length - 1)
+ node.appendChild(document.createElement("br"));
}
}
}
« no previous file with comments | « Source/devtools/front_end/CodeMirrorUtils.js ('k') | Source/devtools/front_end/ScriptFormatterWorker.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698