Title: [145370] trunk/Source/WebCore
- Revision
- 145370
- Author
- commit-qu...@webkit.org
- Date
- 2013-03-11 08:59:24 -0700 (Mon, 11 Mar 2013)
Log Message
Web Inspector: [CodeMirror] add token highlight feature
https://bugs.webkit.org/show_bug.cgi?id=112009
Patch by Andrey Lushnikov <lushni...@chromium.org> on 2013-03-11
Reviewed by Pavel Feldman.
Handle CodeMirror's "cursorActivity" event, check selection for being
a word and highlight all its occurrences via CodeMirror.addOverlay method.
No new tests.
* inspector/front-end/CodeMirrorTextEditor.js:
(WebInspector.CodeMirrorTextEditor):
(WebInspector.CodeMirrorTextEditor.TokenHighlighter):
(WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._cursorChange):
(WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._isWord):
(WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._removeHighlight):
(WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._addHighlight.nextToken):
(WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._addHighlight):
* inspector/front-end/cm/cmdevtools.css:
(.cm-token-highlight):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (145369 => 145370)
--- trunk/Source/WebCore/ChangeLog 2013-03-11 15:51:56 UTC (rev 145369)
+++ trunk/Source/WebCore/ChangeLog 2013-03-11 15:59:24 UTC (rev 145370)
@@ -1,5 +1,28 @@
2013-03-11 Andrey Lushnikov <lushni...@chromium.org>
+ Web Inspector: [CodeMirror] add token highlight feature
+ https://bugs.webkit.org/show_bug.cgi?id=112009
+
+ Reviewed by Pavel Feldman.
+
+ Handle CodeMirror's "cursorActivity" event, check selection for being
+ a word and highlight all its occurrences via CodeMirror.addOverlay method.
+
+ No new tests.
+
+ * inspector/front-end/CodeMirrorTextEditor.js:
+ (WebInspector.CodeMirrorTextEditor):
+ (WebInspector.CodeMirrorTextEditor.TokenHighlighter):
+ (WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._cursorChange):
+ (WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._isWord):
+ (WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._removeHighlight):
+ (WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._addHighlight.nextToken):
+ (WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._addHighlight):
+ * inspector/front-end/cm/cmdevtools.css:
+ (.cm-token-highlight):
+
+2013-03-11 Andrey Lushnikov <lushni...@chromium.org>
+
Web Inspector: [CodeMirror] set indentation size according to devtools settings
https://bugs.webkit.org/show_bug.cgi?id=111717
Modified: trunk/Source/WebCore/inspector/front-end/CodeMirrorTextEditor.js (145369 => 145370)
--- trunk/Source/WebCore/inspector/front-end/CodeMirrorTextEditor.js 2013-03-11 15:51:56 UTC (rev 145369)
+++ trunk/Source/WebCore/inspector/front-end/CodeMirrorTextEditor.js 2013-03-11 15:59:24 UTC (rev 145370)
@@ -64,6 +64,8 @@
this._codeMirror.setOption("indentUnit", indent.length);
}
+ this._tokenHighlighter = new WebInspector.CodeMirrorTextEditor.TokenHighlighter(this._codeMirror);
+
this._codeMirror.on("change", this._change.bind(this));
this._codeMirror.on("gutterClick", this._gutterClick.bind(this));
this.element.addEventListener("contextmenu", this._contextMenu.bind(this));
@@ -417,3 +419,60 @@
__proto__: WebInspector.View.prototype
}
+
+WebInspector.CodeMirrorTextEditor.TokenHighlighter = function(codeMirror)
+{
+ this._codeMirror = codeMirror;
+ this._codeMirror.on("cursorActivity", this._cursorChange.bind(this));
+}
+
+WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype = {
+ _cursorChange: function()
+ {
+ this._codeMirror.operation(this._removeHighlight.bind(this));
+ var selectionStart = this._codeMirror.getCursor("start");
+ var selectionEnd = this._codeMirror.getCursor("end");
+ if (selectionStart.line !== selectionEnd.line)
+ return;
+ if (selectionStart.ch === selectionEnd.ch)
+ return;
+
+ var selectedText = this._codeMirror.getSelection();
+ if (this._isWord(selectedText, selectionStart.line, selectionStart.ch, selectionEnd.ch))
+ this._codeMirror.operation(this._addHighlight.bind(this, selectedText));
+ },
+
+ _isWord: function(selectedText, lineNumber, startColumn, endColumn)
+ {
+ var line = this._codeMirror.getLine(lineNumber);
+ var leftBound = startColumn === 0 || !WebInspector.TextUtils.isWordChar(line.charAt(startColumn - 1));
+ var rightBound = endColumn === line.length || !WebInspector.TextUtils.isWordChar(line.charAt(endColumn));
+ return leftBound && rightBound && WebInspector.TextUtils.isWord(selectedText);
+ },
+
+ _removeHighlight: function()
+ {
+ if (this._overlayMode) {
+ this._codeMirror.removeOverlay(this._overlayMode);
+ delete this._overlayMode;
+ }
+ },
+
+ _addHighlight: function(token)
+ {
+ const tokenFirstChar = token.charAt(0);
+ function nextToken(stream)
+ {
+ if (stream.match(token))
+ return "token-highlight";
+ stream.next();
+ if (!stream.skipTo(tokenFirstChar))
+ stream.skipToEnd();
+ }
+
+ this._overlayMode = {
+ token: nextToken
+ };
+ this._codeMirror.addOverlay(this._overlayMode);
+ }
+}
Modified: trunk/Source/WebCore/inspector/front-end/cm/cmdevtools.css (145369 => 145370)
--- trunk/Source/WebCore/inspector/front-end/cm/cmdevtools.css 2013-03-11 15:51:56 UTC (rev 145369)
+++ trunk/Source/WebCore/inspector/front-end/cm/cmdevtools.css 2013-03-11 15:59:24 UTC (rev 145370)
@@ -39,6 +39,12 @@
outline: 1px solid rgb(64, 115, 244);
}
+.cm-token-highlight {
+ border: 1px solid gray;
+ border-radius: 3px;
+ margin: -1px;
+}
+
.cm-s-web-inspector-js span.cm-keyword {color: rgb(170, 13, 145);}
.cm-s-web-inspector-js span.cm-number {color: rgb(28, 0, 207);}
.cm-s-web-inspector-js span.cm-comment {color: rgb(0, 116, 0);}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes