Title: [259738] trunk/Source/WebInspectorUI
Revision
259738
Author
[email protected]
Date
2020-04-08 11:53:10 -0700 (Wed, 08 Apr 2020)

Log Message

Web Inspector: Sources: support copying selected call frame(s) in the Call Stack
https://bugs.webkit.org/show_bug.cgi?id=210172

Reviewed by Timothy Hatcher.

* UserInterface/Views/SourcesTabContentView.js:
(WI.SourcesTabContentView.prototype.handleCopyEvent): Added.
* UserInterface/Views/SourcesNavigationSidebarPanel.js:
(WI.SourcesNavigationSidebarPanel):
(WI.SourcesNavigationSidebarPanel.prototype.handleCopyEvent): Added.
Copy the function name and source location for each selected call frame. If the selected
call frames span an async boundary, include the async boundary in the form `--- <name> ---`
where name is the reason for the async behavior (e.g. `addEventListener`). If the selected
call frames span multiple threads (e.g. `Worker`), include the thread name and indent all
of the call frames for that thread.

* UserInterface/Views/CallFrameTreeElement.js:
(WI.CallFrameTreeElement):
(WI.CallFrameTreeElement.prototype.get isAsyncBoundaryCallFrame): Added.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (259737 => 259738)


--- trunk/Source/WebInspectorUI/ChangeLog	2020-04-08 18:50:43 UTC (rev 259737)
+++ trunk/Source/WebInspectorUI/ChangeLog	2020-04-08 18:53:10 UTC (rev 259738)
@@ -1,3 +1,25 @@
+2020-04-08  Devin Rousso  <[email protected]>
+
+        Web Inspector: Sources: support copying selected call frame(s) in the Call Stack
+        https://bugs.webkit.org/show_bug.cgi?id=210172
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Views/SourcesTabContentView.js:
+        (WI.SourcesTabContentView.prototype.handleCopyEvent): Added.
+        * UserInterface/Views/SourcesNavigationSidebarPanel.js:
+        (WI.SourcesNavigationSidebarPanel):
+        (WI.SourcesNavigationSidebarPanel.prototype.handleCopyEvent): Added.
+        Copy the function name and source location for each selected call frame. If the selected
+        call frames span an async boundary, include the async boundary in the form `--- <name> ---`
+        where name is the reason for the async behavior (e.g. `addEventListener`). If the selected
+        call frames span multiple threads (e.g. `Worker`), include the thread name and indent all
+        of the call frames for that thread.
+
+        * UserInterface/Views/CallFrameTreeElement.js:
+        (WI.CallFrameTreeElement):
+        (WI.CallFrameTreeElement.prototype.get isAsyncBoundaryCallFrame): Added.
+
 2020-04-07  Nikita Vasilyev  <[email protected]>
 
         Web Inspector: focus outline of scope bar is clipped

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CallFrameTreeElement.js (259737 => 259738)


--- trunk/Source/WebInspectorUI/UserInterface/Views/CallFrameTreeElement.js	2020-04-08 18:50:43 UTC (rev 259737)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CallFrameTreeElement.js	2020-04-08 18:53:10 UTC (rev 259738)
@@ -37,7 +37,8 @@
         this._callFrame = callFrame;
         this._isActiveCallFrame = false;
 
-         if (isAsyncBoundaryCallFrame) {
+        this._isAsyncBoundaryCallFrame = isAsyncBoundaryCallFrame;
+         if (this._isAsyncBoundaryCallFrame) {
             this.addClassName("async-boundary");
             this.selectable = false;
          }
@@ -66,8 +67,13 @@
     // Public
 
     get callFrame() { return this._callFrame; }
-    get isActiveCallFrame() { return this._isActiveCallFrame; }
+    get isAsyncBoundaryCallFrame() { return this._isAsyncBoundaryCallFrame; }
 
+    get isActiveCallFrame()
+    {
+        return this._isActiveCallFrame;
+    }
+
     set isActiveCallFrame(x)
     {
         if (this._isActiveCallFrame === x)

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SourcesNavigationSidebarPanel.js (259737 => 259738)


--- trunk/Source/WebInspectorUI/UserInterface/Views/SourcesNavigationSidebarPanel.js	2020-04-08 18:50:43 UTC (rev 259737)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SourcesNavigationSidebarPanel.js	2020-04-08 18:53:10 UTC (rev 259738)
@@ -122,8 +122,20 @@
         this._pauseReasonContainer.appendChild(this._pauseReasonSection.element);
 
         this._callStackTreeOutline = this.createContentTreeOutline({suppressFiltering: true});
+        this._callStackTreeOutline.allowsMultipleSelection = true;
         this._callStackTreeOutline.addEventListener(WI.TreeOutline.Event.SelectionDidChange, this._handleTreeSelectionDidChange, this);
+        this._callStackTreeOutline.populateContextMenu = (contextMenu, event, treeElement) => {
+            if (this._callStackTreeOutline.selectedTreeElements.length) {
+                contextMenu.appendItem(WI.UIString("Copy"), () => {
+                    this.handleCopyEvent(event);
+                });
 
+                contextMenu.appendSeparator();
+            }
+
+            WI.TreeOutline.prototype.populateContextMenu(contextMenu, event, treeElement);
+        };
+
         let callStackRow = new WI.DetailsSectionRow;
         callStackRow.element.appendChild(this._callStackTreeOutline.element);
 
@@ -582,6 +594,79 @@
         return null;
     }
 
+    handleCopyEvent(event)
+    {
+        let selectedTreeElements = new Set(this._callStackTreeOutline.selectedTreeElements);
+        if (!selectedTreeElements.size)
+            return;
+
+        let treeElement = this._callStackTreeOutline.children[0];
+
+        const ignoreHidden = true;
+        const skipUnrevealed = true;
+        const stayWithin = null;
+        const dontPopulate = true;
+        while (!treeElement.revealed(ignoreHidden))
+            treeElement = treeElement.traverseNextTreeElement(skipUnrevealed, stayWithin, dontPopulate);
+
+        let indentString = WI.indentString();
+        let threads = [];
+        let asyncBoundary = null;
+
+        while (treeElement) {
+            if (treeElement instanceof WI.ThreadTreeElement) {
+                threads.push({
+                    name: treeElement.mainTitle,
+                    frames: [],
+                });
+
+                asyncBoundary = null;
+            } else if (treeElement instanceof WI.CallFrameTreeElement) {
+                if (treeElement.isAsyncBoundaryCallFrame) {
+                    asyncBoundary = treeElement.mainTitle;
+                } else if (selectedTreeElements.has(treeElement)) {
+                    if (asyncBoundary) {
+                        threads.lastValue.frames.push("--- " + asyncBoundary + " ---");
+                        asyncBoundary = null;
+                    }
+
+                    let line = treeElement.mainTitle;
+
+                    let sourceCodeLocation = treeElement.callFrame.sourceCodeLocation;
+                    if (sourceCodeLocation)
+                        line += " (" + sourceCodeLocation.displayLocationString() + ")";
+
+                    threads.lastValue.frames.push(line);
+                }
+            }
+
+            treeElement = treeElement.traverseNextTreeElement(skipUnrevealed, stayWithin, dontPopulate);
+        }
+
+        let multipleFramesSelected = threads.filter(({frames}) => frames.length).length > 1;
+
+        let lines = [];
+        for (let {name, frames} of threads) {
+            if (multipleFramesSelected)
+                lines.push(name);
+
+            for (let frame of frames) {
+                let prefix = "";
+                if (multipleFramesSelected)
+                    prefix = indentString;
+                lines.push(prefix + frame);
+            }
+        }
+        if (!lines.length)
+            return;
+
+        setTimeout(() => {
+            InspectorFrontendHost.copyText(lines.join("\n"));
+        });
+
+        event.stop();
+    }
+
     // Protected
 
     createContentTreeOutline(options = {})

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SourcesTabContentView.js (259737 => 259738)


--- trunk/Source/WebInspectorUI/UserInterface/Views/SourcesTabContentView.js	2020-04-08 18:50:43 UTC (rev 259737)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SourcesTabContentView.js	2020-04-08 18:53:10 UTC (rev 259738)
@@ -108,6 +108,12 @@
             treeElement.revealAndSelect();
     }
 
+    handleCopyEvent(event)
+    {
+        if (this.navigationSidebarPanel.element.contains(WI.currentFocusElement))
+            this.navigationSidebarPanel.handleCopyEvent(event);
+    }
+
     // Private
 
     _handleDebuggerPaused(event)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to