<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[186490] trunk/Source/WebInspectorUI</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/186490">186490</a></dd>
<dt>Author</dt> <dd>drousso@apple.com</dd>
<dt>Date</dt> <dd>2015-07-07 22:27:17 -0700 (Tue, 07 Jul 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Inspector: Pressing tab on a comment in the styles sidebar doesn't highlight the comment
https://bugs.webkit.org/show_bug.cgi?id=146709

Reviewed by Timothy Hatcher.

* UserInterface/Views/CSSStyleDeclarationTextEditor.js:
(WebInspector.CSSStyleDeclarationTextEditor.prototype.selectFirstProperty):
(WebInspector.CSSStyleDeclarationTextEditor.prototype.selectLastProperty):
(WebInspector.CSSStyleDeclarationTextEditor.prototype._textAtCursorIsComment):
(WebInspector.CSSStyleDeclarationTextEditor.prototype._highlightNextNameOrValue):
(WebInspector.CSSStyleDeclarationTextEditor.prototype._handleMouseUp):
(WebInspector.CSSStyleDeclarationTextEditor.prototype._handleEnterKey):
(WebInspector.CSSStyleDeclarationTextEditor.prototype._insertNewlineAfterCurrentLine):
Determines if the text at the given cursor position in the given line is a comment.
(WebInspector.CSSStyleDeclarationTextEditor.prototype._handleShiftTabKey):
(WebInspector.CSSStyleDeclarationTextEditor.prototype._handleTabKey):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsCSSStyleDeclarationTextEditorjs">trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (186489 => 186490)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/ChangeLog        2015-07-08 05:24:35 UTC (rev 186489)
+++ trunk/Source/WebInspectorUI/ChangeLog        2015-07-08 05:27:17 UTC (rev 186490)
</span><span class="lines">@@ -1,5 +1,24 @@
</span><span class="cx"> 2015-07-07  Devin Rousso  &lt;drousso@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Web Inspector: Pressing tab on a comment in the styles sidebar doesn't highlight the comment
+        https://bugs.webkit.org/show_bug.cgi?id=146709
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Views/CSSStyleDeclarationTextEditor.js:
+        (WebInspector.CSSStyleDeclarationTextEditor.prototype.selectFirstProperty):
+        (WebInspector.CSSStyleDeclarationTextEditor.prototype.selectLastProperty):
+        (WebInspector.CSSStyleDeclarationTextEditor.prototype._textAtCursorIsComment):
+        (WebInspector.CSSStyleDeclarationTextEditor.prototype._highlightNextNameOrValue):
+        (WebInspector.CSSStyleDeclarationTextEditor.prototype._handleMouseUp):
+        (WebInspector.CSSStyleDeclarationTextEditor.prototype._handleEnterKey):
+        (WebInspector.CSSStyleDeclarationTextEditor.prototype._insertNewlineAfterCurrentLine):
+        Determines if the text at the given cursor position in the given line is a comment.
+        (WebInspector.CSSStyleDeclarationTextEditor.prototype._handleShiftTabKey):
+        (WebInspector.CSSStyleDeclarationTextEditor.prototype._handleTabKey):
+
+2015-07-07  Devin Rousso  &lt;drousso@apple.com&gt;
+
</ins><span class="cx">         Web Inspector: spacebar should pause/resume timeline recording when timelines are open
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=143267
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsCSSStyleDeclarationTextEditorjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js (186489 => 186490)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js        2015-07-08 05:24:35 UTC (rev 186489)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js        2015-07-08 05:27:17 UTC (rev 186490)
</span><span class="lines">@@ -358,7 +358,9 @@
</span><span class="cx">             this.clearSelection();
</span><span class="cx"> 
</span><span class="cx">         var index = line.indexOf(&quot;:&quot;);
</span><del>-        this._codeMirror.setSelection({line: 0, ch: 0}, {line: 0, ch: index &lt; 0 ? trimmedLine.length : index});
</del><ins>+        var cursor = {line: 0, ch: 0};
+
+        this._codeMirror.setSelection(cursor, {line: 0, ch: index &lt; 0 || this._textAtCursorIsComment(this._codeMirror, cursor) ? trimmedLine.length : index});
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     selectLastProperty()
</span><span class="lines">@@ -367,8 +369,19 @@
</span><span class="cx">         var lineText = this._codeMirror.getLine(line);
</span><span class="cx">         var trimmedLine = lineText.trimRight();
</span><span class="cx"> 
</span><del>-        var colon = /(?::\s*)/.exec(lineText);
-        this._codeMirror.setSelection({line, ch: colon ? colon.index + colon[0].length : 0}, {line, ch: trimmedLine.length - trimmedLine.endsWith(&quot;;&quot;)});
</del><ins>+        var lastAnchor;
+        var lastHead;
+
+        if (this._textAtCursorIsComment(this._codeMirror, {line, ch: line.length})) {
+            lastAnchor = 0;
+            lastHead = line.length;
+        } else {
+            var colon = /(?::\s*)/.exec(lineText);
+            lastAnchor = colon ? colon.index + colon[0].length : 0;
+            lastHead = trimmedLine.length - trimmedLine.endsWith(&quot;;&quot;);
+        }
+
+        this._codeMirror.setSelection({line, ch: lastAnchor}, {line, ch: lastHead});
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Protected
</span><span class="lines">@@ -395,16 +408,33 @@
</span><span class="cx"> 
</span><span class="cx">     // Private
</span><span class="cx"> 
</span><ins>+    _textAtCursorIsComment(codeMirror, cursor)
+    {
+        var token = codeMirror.getTokenTypeAt(cursor);
+        return token &amp;&amp; token.includes(&quot;comment&quot;);
+    }
+
</ins><span class="cx">     _highlightNextNameOrValue(codeMirror, cursor, text)
</span><span class="cx">     {
</span><del>-        var colonIndex = text.indexOf(&quot;:&quot;);
-        var substringIndex = colonIndex &gt;= 0 &amp;&amp; cursor.ch &gt;= colonIndex ? colonIndex : 0;
</del><ins>+        var nextAnchor;
+        var nextHead;
</ins><span class="cx"> 
</span><del>-        var regExp = /(?:[^:;\s]\s*)+/g;
-        regExp.lastIndex = substringIndex;
-        var match = regExp.exec(text);
</del><ins>+        if (this._textAtCursorIsComment(codeMirror, cursor)) {
+            nextAnchor = 0;
+            nextHead = text.length;
+        } else {
+            var colonIndex = text.indexOf(&quot;:&quot;);
+            var substringIndex = colonIndex &gt;= 0 &amp;&amp; cursor.ch &gt;= colonIndex ? colonIndex : 0;
</ins><span class="cx"> 
</span><del>-        codeMirror.setSelection({line: cursor.line, ch: match.index}, {line: cursor.line, ch: match.index + match[0].length});
</del><ins>+            var regExp = /(?:[^:;\s]\s*)+/g;
+            regExp.lastIndex = substringIndex;
+            var match = regExp.exec(text);
+
+            nextAnchor = match.index;
+            nextHead = nextAnchor + match[0].length;
+        }
+
+        codeMirror.setSelection({line: cursor.line, ch: nextAnchor}, {line: cursor.line, ch: nextHead});
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     _handleMouseDown(event)
</span><span class="lines">@@ -435,9 +465,15 @@
</span><span class="cx">         var cursor = this._codeMirror.coordsChar({left: event.x, top: event.y});
</span><span class="cx">         var line = this._codeMirror.getLine(cursor.line);
</span><span class="cx"> 
</span><del>-        if (this._mouseDownCursorPosition.line === cursor.line &amp;&amp; this._mouseDownCursorPosition.ch === cursor.ch)
-            this._codeMirror.replaceRange(line.trimRight().endsWith(&quot;;&quot;) ? &quot;\n&quot; : &quot;;\n&quot;, cursor);
</del><ins>+        if (this._mouseDownCursorPosition.line === cursor.line &amp;&amp; this._mouseDownCursorPosition.ch === cursor.ch) {
+            var replacement = &quot;\n&quot;;
</ins><span class="cx"> 
</span><ins>+            if (!line.trimRight().endsWith(&quot;;&quot;) &amp;&amp; !this._textAtCursorIsComment(this._codeMirror, cursor))
+                replacement = &quot;;&quot; + replacement;
+
+            this._codeMirror.replaceRange(replacement, cursor);
+        }
+
</ins><span class="cx">         this._mouseDownCursorPosition = null;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -469,7 +505,12 @@
</span><span class="cx">             ++cursor.ch;
</span><span class="cx"> 
</span><span class="cx">         if (cursor.ch === trimmedLine.length) {
</span><del>-            codeMirror.replaceRange(hasEndingSemicolon ? &quot;\n&quot; : &quot;;\n&quot;, cursor);
</del><ins>+            var replacement = &quot;\n&quot;;
+
+            if (!hasEndingSemicolon &amp;&amp; !this._textAtCursorIsComment(this._codeMirror, cursor))
+                replacement = &quot;;&quot; + replacement;
+
+            this._codeMirror.replaceRange(replacement, cursor);
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -485,7 +526,12 @@
</span><span class="cx">         cursor.ch = trimmedLine.length;
</span><span class="cx"> 
</span><span class="cx">         if (cursor.ch) {
</span><del>-            codeMirror.replaceRange(trimmedLine.endsWith(&quot;;&quot;) ? &quot;\n&quot; : &quot;;\n&quot;, cursor);
</del><ins>+            var replacement = &quot;\n&quot;;
+
+            if (!trimmedLine.endsWith(&quot;;&quot;) &amp;&amp; !this._textAtCursorIsComment(this._codeMirror, cursor))
+                replacement = &quot;;&quot; + replacement;
+
+            this._codeMirror.replaceRange(replacement, cursor);
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -507,15 +553,29 @@
</span><span class="cx">         var cursor = codeMirror.getCursor();
</span><span class="cx">         var line = codeMirror.getLine(cursor.line);
</span><span class="cx">         var previousLine = codeMirror.getLine(cursor.line - 1);
</span><del>-        var trimmedPreviousLine = previousLine ? previousLine.trimRight() : &quot;&quot;;
</del><span class="cx"> 
</span><span class="cx">         if (!line &amp;&amp; !previousLine &amp;&amp; !cursor.line)
</span><span class="cx">             return switchRule.call(this);
</span><span class="cx"> 
</span><del>-        if (cursor.ch === line.indexOf(&quot;:&quot;) || line.indexOf(&quot;:&quot;) &lt; 0) {
</del><ins>+        var trimmedPreviousLine = previousLine ? previousLine.trimRight() : &quot;&quot;;
+        var previousAnchor;
+        var previousHead;
+        var isComment = this._textAtCursorIsComment(codeMirror, cursor);
+
+        if (cursor.ch === line.indexOf(&quot;:&quot;) || line.indexOf(&quot;:&quot;) &lt; 0 || isComment) {
</ins><span class="cx">             if (previousLine) {
</span><del>-                var colon = /(?::\s*)/.exec(previousLine);
-                codeMirror.setSelection({line: cursor.line - 1, ch: colon ? colon.index + colon[0].length : 0}, {line: cursor.line - 1, ch: trimmedPreviousLine.length - trimmedPreviousLine.endsWith(&quot;;&quot;)});
</del><ins>+                --cursor.line;
+
+                if (this._textAtCursorIsComment(codeMirror, cursor)) {
+                    previousAnchor = 0;
+                    previousHead = trimmedPreviousLine.length;
+                } else {
+                    var colon = /(?::\s*)/.exec(previousLine);
+                    previousAnchor = colon ? colon.index + colon[0].length : 0;
+                    previousHead = trimmedPreviousLine.length - trimmedPreviousLine.endsWith(&quot;;&quot;);
+                }
+                
+                codeMirror.setSelection({line: cursor.line, ch: previousAnchor}, {line: cursor.line, ch: previousHead});
</ins><span class="cx">                 return;
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="lines">@@ -527,8 +587,16 @@
</span><span class="cx">             return switchRule.call(this);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        var match = /(?:[^:;\s]\s*)+/.exec(line);
-        codeMirror.setSelection({line: cursor.line, ch: match.index}, {line: cursor.line, ch: match.index + match[0].length});
</del><ins>+        if (isComment) {
+            previousAnchor = 0;
+            previousHead = line.length;
+        } else {
+            var match = /(?:[^:;\s]\s*)+/.exec(line);
+            previousAnchor = match.index;
+            previousHead = previousAnchor + match[0].length;
+        }
+
+        codeMirror.setSelection({line: cursor.line, ch: previousAnchor}, {line: cursor.line, ch: previousHead});
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     _handleTabKey(codeMirror)
</span><span class="lines">@@ -578,7 +646,7 @@
</span><span class="cx"> 
</span><span class="cx">                 var replacement = &quot;&quot;;
</span><span class="cx"> 
</span><del>-                if (!hasEndingSemicolon)
</del><ins>+                if (!hasEndingSemicolon &amp;&amp; !this._textAtCursorIsComment(codeMirror, cursor))
</ins><span class="cx">                     replacement += &quot;;&quot;;
</span><span class="cx"> 
</span><span class="cx">                 if (lastLine)
</span><span class="lines">@@ -592,8 +660,7 @@
</span><span class="cx">                     return;
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                var colon = nextLine.indexOf(&quot;:&quot;);
-                codeMirror.setSelection({line: cursor.line + 1, ch: 0}, {line: cursor.line + 1, ch: colon &lt; 0 ? trimmedNextLine.length : colon});
</del><ins>+                this._highlightNextNameOrValue(codeMirror, {line: cursor.line + 1, ch: 0}, nextLine);
</ins><span class="cx">             }.bind(this));
</span><span class="cx"> 
</span><span class="cx">             return;
</span></span></pre>
</div>
</div>

</body>
</html>