Title: [205223] trunk/Source/WebInspectorUI
Revision
205223
Author
[email protected]
Date
2016-08-30 23:21:05 -0700 (Tue, 30 Aug 2016)

Log Message

Web Inspector: Remove largest common indentation spacing in debugger popover
https://bugs.webkit.org/show_bug.cgi?id=161417

Patch by Devin Rousso <[email protected]> on 2016-08-30
Reviewed by Joseph Pecoraro.

* UserInterface/Views/SourceCodeTextEditor.css:
(.popover .debugger-popover-content.function > .body):
(.popover .debugger-popover-content.function > .body .CodeMirror):

* UserInterface/Views/SourceCodeTextEditor.js:
(WebInspector.SourceCodeTextEditor.prototype._showPopoverForFunction.didGetDetails):
Use CodeMirror and FormatterWorker to display a non-editable popover.

* UserInterface/Workers/Formatter/FormatterWorker.js:
(FormatterWorker.prototype.formatJavaScript):
Reworked logic to always attempt to format by wrapping content in "(...)".  This is
necessary for unnamed functions, since they are not valid programs by themselves.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (205222 => 205223)


--- trunk/Source/WebInspectorUI/ChangeLog	2016-08-31 05:59:02 UTC (rev 205222)
+++ trunk/Source/WebInspectorUI/ChangeLog	2016-08-31 06:21:05 UTC (rev 205223)
@@ -1,3 +1,23 @@
+2016-08-30  Devin Rousso  <[email protected]>
+
+        Web Inspector: Remove largest common indentation spacing in debugger popover
+        https://bugs.webkit.org/show_bug.cgi?id=161417
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/Views/SourceCodeTextEditor.css:
+        (.popover .debugger-popover-content.function > .body):
+        (.popover .debugger-popover-content.function > .body .CodeMirror):
+
+        * UserInterface/Views/SourceCodeTextEditor.js:
+        (WebInspector.SourceCodeTextEditor.prototype._showPopoverForFunction.didGetDetails):
+        Use CodeMirror and FormatterWorker to display a non-editable popover.
+
+        * UserInterface/Workers/Formatter/FormatterWorker.js:
+        (FormatterWorker.prototype.formatJavaScript):
+        Reworked logic to always attempt to format by wrapping content in "(...)".  This is
+        necessary for unnamed functions, since they are not valid programs by themselves.
+
 2016-08-30  Johan K. Jensen  <[email protected]>
 
         Web Inspector: Add resource timing model with timing information

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.css (205222 => 205223)


--- trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.css	2016-08-31 05:59:02 UTC (rev 205222)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.css	2016-08-31 06:21:05 UTC (rev 205223)
@@ -168,10 +168,16 @@
 }
 
 .popover .debugger-popover-content.function > .body {
+    min-width: 200px;
     padding-left: 10px;
     padding-right: 10px;
 }
 
+.popover .debugger-popover-content.function > .body .CodeMirror {
+    height: auto;
+    background-color: inherit;
+}
+
 /* Custom styling for the hover menu attached to color tokens */
 
 .hover-menu.color {

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js (205222 => 205223)


--- trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js	2016-08-31 05:59:02 UTC (rev 205222)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js	2016-08-31 06:21:05 UTC (rev 205223)
@@ -1473,25 +1473,38 @@
             if (candidate !== this.tokenTrackingController.candidate)
                 return;
 
-            let wrapper = document.createElement("div");
-            wrapper.classList.add("body", "formatted-function");
-            wrapper.textContent = data.description;
-
             let content = document.createElement("div");
             content.classList.add("function");
 
+            let title = document.createElement("div");
+            title.classList.add("title");
+            title.textContent = response.name || response.displayName || WebInspector.UIString("(anonymous function)");
+            content.appendChild(title);
+
             let location = response.location;
             let sourceCode = WebInspector.debuggerManager.scriptForIdentifier(location.scriptId);
             let sourceCodeLocation = sourceCode.createSourceCodeLocation(location.lineNumber, location.columnNumber);
             let functionSourceCodeLink = WebInspector.createSourceCodeLocationLink(sourceCodeLocation);
-
-            let title = content.appendChild(document.createElement("div"));
-            title.classList.add("title");
-            title.textContent = response.name || response.displayName || WebInspector.UIString("(anonymous function)");
             title.appendChild(functionSourceCodeLink);
 
+            let wrapper = document.createElement("div");
+            wrapper.classList.add("body");
             content.appendChild(wrapper);
 
+            let codeMirror = WebInspector.CodeMirrorEditor.create(wrapper, {
+                mode: "text/_javascript_",
+                readOnly: "nocursor",
+            });
+            codeMirror.on("update", () => {
+                this._popover.update();
+            });
+
+            // FIXME: <rdar://problem/10593948> Provide a way to change the tab width in the Web Inspector
+            let workerProxy = WebInspector.FormatterWorkerProxy.singleton();
+            workerProxy.formatJavaScript(data.description, "    ", false, ({formattedText}) => {
+                codeMirror.setValue(formattedText || data.description);
+            });
+
             this._showPopover(content);
         }
         DebuggerAgent.getFunctionDetails(data.objectId, didGetDetails.bind(this));

Modified: trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/FormatterWorker.js (205222 => 205223)


--- trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/FormatterWorker.js	2016-08-31 05:59:02 UTC (rev 205222)
+++ trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/FormatterWorker.js	2016-08-31 06:21:05 UTC (rev 205223)
@@ -68,18 +68,19 @@
             return result;
         } catch (e) {}
 
-        // Format invalid JSON.
+        // Format invalid JSON and anonymous functions.
         // Some applications do not use JSON.parse but eval on JSON content. That is more permissive
         // so try to format invalid JSON. Again no source map data since it is not code.
-        if (/^\s*\{/.test(sourceText)) {
-            let invalidJSONFormatter = new EsprimaFormatter("(" + sourceText + ")", indentString);
-            if (invalidJSONFormatter.success) {
-                let formattedTextWithParens = invalidJSONFormatter.formattedText;
-                let result = {formattedText: formattedTextWithParens.substring(1, formattedTextWithParens.length - 2)}; // Remove "(" and ")\n".
-                if (includeSourceMapData)
-                    result.sourceMapData = {mapping: {original: [], formatted: []}, originalLineEndings:[], formattedLineEndings: []};
-                return result;
-            }
+        // Likewise, an unnamed function's toString() produces a "function() { ... }", which is not
+        // a valid program on its own. Wrap it in parenthesis to make it a function _expression_,
+        // which is a valid program.
+        let invalidJSONFormatter = new EsprimaFormatter("(" + sourceText + ")", indentString);
+        if (invalidJSONFormatter.success) {
+            let formattedTextWithParens = invalidJSONFormatter.formattedText;
+            let result = {formattedText: formattedTextWithParens.substring(1, formattedTextWithParens.length - 2)}; // Remove "(" and ")\n".
+            if (includeSourceMapData)
+                result.sourceMapData = {mapping: {original: [], formatted: []}, originalLineEndings:[], formattedLineEndings: []};
+            return result;
         }
 
         return {formattedText: null};
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to