Title: [206655] trunk/Source/WebInspectorUI
Revision
206655
Author
[email protected]
Date
2016-09-30 12:24:32 -0700 (Fri, 30 Sep 2016)

Log Message

Web Inspector: Make debugger stepping highlights work in inline <script>s
https://bugs.webkit.org/show_bug.cgi?id=162753
<rdar://problem/28551332>

Reviewed by Brian Burg.

* UserInterface/Models/TextRange.js:
(WebInspector.TextRange.prototype.contains):
Check if a given line/column falls within this range.

* UserInterface/Views/SourceCodeTextEditor.js:
(WebInspector.SourceCodeTextEditor.prototype._getAssociatedScript):
If we are in a Document resource find the associated script at a given position.

(WebInspector.SourceCodeTextEditor.prototype.textEditorExecutionHighlightRange):
When comparing offsets to SyntaxTree offsets, the SyntaxTree's offset of 0 is the
first character of the Script, which differs from the current SourceCode's offset.
Adjust the offset by the Script's startOffset.

* UserInterface/Views/TextEditor.js:
(WebInspector.TextEditor.prototype.currentPositionToOriginalPosition):
(WebInspector.TextEditor.prototype._updateExecutionRangeHighlight):
Pass both the original offset and original position to the delegate.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (206654 => 206655)


--- trunk/Source/WebInspectorUI/ChangeLog	2016-09-30 19:24:29 UTC (rev 206654)
+++ trunk/Source/WebInspectorUI/ChangeLog	2016-09-30 19:24:32 UTC (rev 206655)
@@ -1,5 +1,31 @@
 2016-09-30  Joseph Pecoraro  <[email protected]>
 
+        Web Inspector: Make debugger stepping highlights work in inline <script>s
+        https://bugs.webkit.org/show_bug.cgi?id=162753
+        <rdar://problem/28551332>
+
+        Reviewed by Brian Burg.
+
+        * UserInterface/Models/TextRange.js:
+        (WebInspector.TextRange.prototype.contains):
+        Check if a given line/column falls within this range.
+
+        * UserInterface/Views/SourceCodeTextEditor.js:
+        (WebInspector.SourceCodeTextEditor.prototype._getAssociatedScript):
+        If we are in a Document resource find the associated script at a given position.
+
+        (WebInspector.SourceCodeTextEditor.prototype.textEditorExecutionHighlightRange):
+        When comparing offsets to SyntaxTree offsets, the SyntaxTree's offset of 0 is the
+        first character of the Script, which differs from the current SourceCode's offset.
+        Adjust the offset by the Script's startOffset.
+
+        * UserInterface/Views/TextEditor.js:
+        (WebInspector.TextEditor.prototype.currentPositionToOriginalPosition):
+        (WebInspector.TextEditor.prototype._updateExecutionRangeHighlight):
+        Pass both the original offset and original position to the delegate.
+
+2016-09-30  Joseph Pecoraro  <[email protected]>
+
         Web Inspector: Stepping through `a(); b(); c();` it is unclear where we are and what is about to execute
         https://bugs.webkit.org/show_bug.cgi?id=161658
         <rdar://problem/28181254>

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/FormatterSourceMap.js (206654 => 206655)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/FormatterSourceMap.js	2016-09-30 19:24:29 UTC (rev 206654)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/FormatterSourceMap.js	2016-09-30 19:24:32 UTC (rev 206655)
@@ -55,7 +55,6 @@
         return this._positionToLocation(this._formattedLineEndings, formattedPosition);
     }
 
-
     formattedToOriginal(lineNumber, columnNumber)
     {
         var originalPosition = this.formattedToOriginalOffset(lineNumber, columnNumber);

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/TextRange.js (206654 => 206655)


--- trunk/Source/WebInspectorUI/UserInterface/Models/TextRange.js	2016-09-30 19:24:29 UTC (rev 206654)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/TextRange.js	2016-09-30 19:24:32 UTC (rev 206655)
@@ -96,4 +96,18 @@
 
         this._endOffset = lastNewLineOffset + this._endColumn;
     }
+
+    contains(line, column)
+    {
+        console.assert(!isNaN(this._startLine), "TextRange needs line/column data");
+
+        if (line < this._startLine || line > this._endLine)
+            return false;
+        if (line === this._startLine && column < this._startColumn)
+            return false;
+        if (line === this._endLine && column > this._endColumn)
+            return false;
+
+        return true;
+    }
 };

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js (206654 => 206655)


--- trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js	2016-09-30 19:24:29 UTC (rev 206654)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js	2016-09-30 19:24:32 UTC (rev 206655)
@@ -1210,14 +1210,23 @@
         this._reinsertAllIssues();
     }
 
-    textEditorExecutionHighlightRange(offset, callback)
+    textEditorExecutionHighlightRange(offset, position, callback)
     {
-        let script = this._getAssociatedScript();
+        let script = this._getAssociatedScript(position);
         if (!script) {
             callback(null);
             return;
         }
 
+        // If this is an inline script, then convert to offset within the inline script.
+        let adjustment = script.range.startOffset || 0;
+        offset = offset - adjustment;
+
+        // When returning offsets, convert to offsets within the SourceCode being viewed.
+        function convertRangeOffsetsToSourceCodeOffsets(range) {
+            return range.map((offset) => offset + adjustment);
+        }
+
         script.requestScriptSyntaxTree((syntaxTree) => {
             let nodes = syntaxTree.containersOfOffset(offset);
             if (!nodes.length) {
@@ -1229,7 +1238,7 @@
             for (let node of nodes) {
                 let startOffset = node.range[0];
                 if (startOffset === offset) {
-                    callback(node.range);
+                    callback(convertRangeOffsetsToSourceCodeOffsets(node.range));
                     return;
                 }
                 if (startOffset > offset)
@@ -1245,7 +1254,7 @@
                 if (endOffset === offset) {
                     if (node.type === WebInspector.ScriptSyntaxTree.NodeType.BlockStatement) {
                         // Closing brace of a block, only highlight the closing brace character.
-                        callback([offset - 1, offset]);
+                        callback(convertRangeOffsetsToSourceCodeOffsets([offset - 1, offset]));
                         return;
                     }
                 }
@@ -1267,7 +1276,7 @@
                 // In a function call.
                 if (node.type === WebInspector.ScriptSyntaxTree.NodeType.CallExpression
                     || node.type === WebInspector.ScriptSyntaxTree.NodeType.NewExpression) {
-                    callback(node.range);
+                    callback(convertRangeOffsetsToSourceCodeOffsets(node.range));
                     return;
                 }
 
@@ -1276,10 +1285,10 @@
                     || node.type === WebInspector.ScriptSyntaxTree.NodeType.IdentifierExpression) {
                     let nextNode = nodes[i + 1];
                     if (nextNode && nextNode.type === WebInspector.ScriptSyntaxTree.NodeType.MemberExpression) {
-                        callback(nextNode.range);
+                        callback(convertRangeOffsetsToSourceCodeOffsets(nextNode.range));
                         return;
                     }
-                    callback(node.range);
+                    callback(convertRangeOffsetsToSourceCodeOffsets(node.range));
                     return;
                 }
             }
@@ -1852,14 +1861,27 @@
         WebInspector.enableControlFlowProfilerSetting.value = shouldActivate;
     }
 
-    _getAssociatedScript()
+    _getAssociatedScript(position)
     {
-        var script = null;
-        // FIXME: This needs to me modified to work with HTML files with inline script tags.
+        let script = null;
+
         if (this._sourceCode instanceof WebInspector.Script)
             script = this._sourceCode;
-        else if (this._sourceCode instanceof WebInspector.Resource && this._sourceCode.type === WebInspector.Resource.Type.Script && this._sourceCode.scripts.length)
-            script = this._sourceCode.scripts[0];
+        else if (this._sourceCode instanceof WebInspector.Resource && this._sourceCode.scripts.length) {
+            if (this._sourceCode.type === WebInspector.Resource.Type.Script)
+                script = this._sourceCode.scripts[0];
+            else if (this._sourceCode.type === WebInspector.Resource.Type.Document && position) {
+                for (let inlineScript of this._sourceCode.scripts) {
+                    if (inlineScript.range.contains(position.lineNumber, position.columnNumber)) {
+                        if (isNaN(inlineScript.range.startOffset))
+                            inlineScript.range.resolveOffsets(this._sourceCode.content);
+                        script = inlineScript;
+                        break;
+                    }
+                }
+            }
+        }
+
         return script;
     }
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/TextEditor.js (206654 => 206655)


--- trunk/Source/WebInspectorUI/UserInterface/Views/TextEditor.js	2016-09-30 19:24:29 UTC (rev 206654)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/TextEditor.js	2016-09-30 19:24:32 UTC (rev 206655)
@@ -708,6 +708,15 @@
         return offset;
     }
 
+    currentPositionToOriginalPosition(position)
+    {
+        if (!this._formatterSourceMap)
+            return position;
+
+        let location = this._formatterSourceMap.formattedToOriginal(position.line, position.ch);
+        return {line: location.lineNumber, ch: location.columnNumber};
+    }
+
     currentPositionToCurrentOffset(position)
     {
         return this._codeMirror.getDoc().indexFromPos(position);
@@ -1225,9 +1234,12 @@
         if (isNaN(this._executionLineNumber))
             return;
 
-        let offset = this.currentPositionToOriginalOffset({line: this._executionLineNumber, ch: this._executionColumnNumber});
+        let currentPosition = {line: this._executionLineNumber, ch: this._executionColumnNumber};
+        let originalOffset = this.currentPositionToOriginalOffset(currentPosition);
+        let originalCodeMirrorPosition = this.currentPositionToOriginalPosition(currentPosition);
+        let originalPosition = new WebInspector.SourceCodePosition(originalCodeMirrorPosition.line, originalCodeMirrorPosition.ch);
 
-        this._delegate.textEditorExecutionHighlightRange(offset, (range) => {
+        this._delegate.textEditorExecutionHighlightRange(originalOffset, originalPosition, (range) => {
             let start, end;
             if (!range) {
                 // Highlight the rest of the line.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to