Web Inspector: [CodeMirror] there are bugs in TokenHighlight feature
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Mar 2013 12:15:21 +0000 (12:15 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Mar 2013 12:15:21 +0000 (12:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=112039

Patch by Andrey Lushnikov <lushnikov@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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@145530 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/CodeMirrorTextEditor.js
Source/WebCore/inspector/front-end/cm/cmdevtools.css

index 3134b91..0e7a76b 100644 (file)
@@ -1,3 +1,25 @@
+2013-03-12  Andrey Lushnikov  <lushnikov@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.bot@gmail.com>
 
         Unreviewed, rolling out r145514.
index 9905953..69720a6 100644 (file)
@@ -441,7 +441,7 @@ WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype = {
 
         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 @@ WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype = {
 
     _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
+        };
     }
 }
index 3dca593..7c92498 100644 (file)
     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);}