Title: [145530] trunk/Source/WebCore
Revision
145530
Author
commit-qu...@webkit.org
Date
2013-03-12 05:15:21 -0700 (Tue, 12 Mar 2013)

Log Message

Web Inspector: [CodeMirror] there are bugs in TokenHighlight feature
https://bugs.webkit.org/show_bug.cgi?id=112039

Patch by Andrey Lushnikov <lushni...@chromium.org> on 2013-03-12
Reviewed by Vsevolod Vlasov.

Fix token highlight in codeMirror experiment
- rewrite token highlight overlay mode to highlight words, not
substrings
- add workaround to avoid selection of already selected word

No new tests.

* inspector/front-end/CodeMirrorTextEditor.js:
(WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._cursorChange):
(WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._removeHighlight):
(WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype.nextToken):
(WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._addHighlight):
* inspector/front-end/cm/cmdevtools.css:
(.line-with-selection .cm-column-with-selection):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (145529 => 145530)


--- trunk/Source/WebCore/ChangeLog	2013-03-12 12:11:58 UTC (rev 145529)
+++ trunk/Source/WebCore/ChangeLog	2013-03-12 12:15:21 UTC (rev 145530)
@@ -1,3 +1,25 @@
+2013-03-12  Andrey Lushnikov  <lushni...@chromium.org>
+
+        Web Inspector: [CodeMirror] there are bugs in TokenHighlight feature
+        https://bugs.webkit.org/show_bug.cgi?id=112039
+
+        Reviewed by Vsevolod Vlasov.
+
+        Fix token highlight in codeMirror experiment
+        - rewrite token highlight overlay mode to highlight words, not
+        substrings
+        - add workaround to avoid selection of already selected word
+
+        No new tests.
+
+        * inspector/front-end/CodeMirrorTextEditor.js:
+        (WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._cursorChange):
+        (WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._removeHighlight):
+        (WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype.nextToken):
+        (WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype._addHighlight):
+        * inspector/front-end/cm/cmdevtools.css:
+        (.line-with-selection .cm-column-with-selection):
+
 2013-03-12  Sheriff Bot  <webkit.review....@gmail.com>
 
         Unreviewed, rolling out r145514.

Modified: trunk/Source/WebCore/inspector/front-end/CodeMirrorTextEditor.js (145529 => 145530)


--- trunk/Source/WebCore/inspector/front-end/CodeMirrorTextEditor.js	2013-03-12 12:11:58 UTC (rev 145529)
+++ trunk/Source/WebCore/inspector/front-end/CodeMirrorTextEditor.js	2013-03-12 12:15:21 UTC (rev 145530)
@@ -441,7 +441,7 @@
 
         var selectedText = this._codeMirror.getSelection();
         if (this._isWord(selectedText, selectionStart.line, selectionStart.ch, selectionEnd.ch))
-            this._codeMirror.operation(this._addHighlight.bind(this, selectedText));
+            this._codeMirror.operation(this._addHighlight.bind(this, selectedText, selectionStart));
     },
 
     _isWord: function(selectedText, lineNumber, startColumn, endColumn)
@@ -454,27 +454,35 @@
 
     _removeHighlight: function()
     {
-        if (this._overlayMode) {
-            this._codeMirror.removeOverlay(this._overlayMode);
-            delete this._overlayMode;
+        if (this._highlightDescriptor) {
+            this._codeMirror.removeOverlay(this._highlightDescriptor.overlay);
+            this._codeMirror.removeLineClass(this._highlightDescriptor.selectionStart.line, "wrap", "cm-line-with-selection");
+            delete this._highlightDescriptor;
         }
     },
 
-    _addHighlight: function(token)
+    _addHighlight: function(token, selectionStart)
     {
         const tokenFirstChar = token.charAt(0);
         function nextToken(stream)
         {
-            if (stream.match(token))
-                return "token-highlight";
-            stream.next();
-            if (!stream.skipTo(tokenFirstChar))
-                stream.skipToEnd();
+            if (stream.match(token) && (stream.eol() || !WebInspector.TextUtils.isWordChar(stream.peek())))
+                return stream.column() === selectionStart.ch ? "token-highlight column-with-selection" : "token-highlight";
+
+            var eatenChar;
+            do {
+                eatenChar = stream.next();
+            } while (eatenChar && (WebInspector.TextUtils.isWordChar(eatenChar) || stream.peek() !== tokenFirstChar));
         }
 
-        this._overlayMode = {
+        var overlayMode = {
             token: nextToken
         };
-        this._codeMirror.addOverlay(this._overlayMode);
+        this._codeMirror.addOverlay(overlayMode);
+        this._codeMirror.addLineClass(selectionStart.line, "wrap", "cm-line-with-selection")
+        this._highlightDescriptor = {
+            overlay: overlayMode,
+            selectionStart: selectionStart
+        };
     }
 }

Modified: trunk/Source/WebCore/inspector/front-end/cm/cmdevtools.css (145529 => 145530)


--- trunk/Source/WebCore/inspector/front-end/cm/cmdevtools.css	2013-03-12 12:11:58 UTC (rev 145529)
+++ trunk/Source/WebCore/inspector/front-end/cm/cmdevtools.css	2013-03-12 12:15:21 UTC (rev 145530)
@@ -56,6 +56,11 @@
     margin: -1px;
 }
 
+.cm-line-with-selection .cm-column-with-selection {
+    border: 0px;
+    margin: 0px;
+}
+
 .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

Reply via email to