Title: [204418] trunk/Source/WebInspectorUI
Revision
204418
Author
[email protected]
Date
2016-08-12 13:34:43 -0700 (Fri, 12 Aug 2016)

Log Message

Web Inspector: Support for :lineNumber syntax in Open Resource Dialog
https://bugs.webkit.org/show_bug.cgi?id=159732
<rdar://problem/27684491>

Patch by Joseph Pecoraro <[email protected]> on 2016-08-12
Reviewed by Matt Baker.

Allow the Open Resource Dialog to support line/column syntax.
Other tools allow "<name>:<line>:<column>" syntax, where the
location data at the end is optional. If the <name> portion
is missing, the location can be used for the active content
view, assuming it has text data and has lines.

* UserInterface/Base/Main.js:
(WebInspector.focusedOrVisibleContentView):
Expose a function to access the current focused / visible content view.

(WebInspector.dialogWasDismissed):
Include passing on cookie data when showing a represented object.

* UserInterface/Views/Dialog.js:
(WebInspector.Dialog):
(WebInspector.Dialog.prototype.get visible):
(WebInspector.Dialog.prototype.get delegate):
(WebInspector.Dialog.prototype.get representedObject):
(WebInspector.Dialog.prototype.get cookie):
(WebInspector.Dialog.prototype.dismiss):
* UserInterface/Models/ResourceQueryResult.js:
(WebInspector.ResourceQueryResult):
(WebInspector.ResourceQueryResult.prototype.get cookie):
Include cookie data along with the represented object in matches
and dialog results.

* UserInterface/Controllers/ResourceQueryController.js:
(WebInspector.ResourceQueryController.prototype.executeQuery):
Cut off location data from a query, and stash it on the query result.
A query can be "<name>:<line>:<column>", and the line/column data
becomes cookie data for the resource.

* UserInterface/Views/OpenResourceDialog.js:
(WebInspector.OpenResourceDialog.prototype._populateResourceTreeOutline):
If the query is just ":<line>:<column>" have it jump to a location
in the current content view if applicable.

(WebInspector.OpenResourceDialog.prototype._handleKeydownEvent):
(WebInspector.OpenResourceDialog.prototype._treeSelectionDidChange):
When dismissing, include cookie data.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (204417 => 204418)


--- trunk/Source/WebInspectorUI/ChangeLog	2016-08-12 20:03:49 UTC (rev 204417)
+++ trunk/Source/WebInspectorUI/ChangeLog	2016-08-12 20:34:43 UTC (rev 204418)
@@ -1,3 +1,52 @@
+2016-08-12  Joseph Pecoraro  <[email protected]>
+
+        Web Inspector: Support for :lineNumber syntax in Open Resource Dialog
+        https://bugs.webkit.org/show_bug.cgi?id=159732
+        <rdar://problem/27684491>
+
+        Reviewed by Matt Baker.
+
+        Allow the Open Resource Dialog to support line/column syntax.
+        Other tools allow "<name>:<line>:<column>" syntax, where the
+        location data at the end is optional. If the <name> portion
+        is missing, the location can be used for the active content
+        view, assuming it has text data and has lines.
+
+        * UserInterface/Base/Main.js:
+        (WebInspector.focusedOrVisibleContentView):
+        Expose a function to access the current focused / visible content view.
+
+        (WebInspector.dialogWasDismissed):
+        Include passing on cookie data when showing a represented object.
+
+        * UserInterface/Views/Dialog.js:
+        (WebInspector.Dialog):
+        (WebInspector.Dialog.prototype.get visible):
+        (WebInspector.Dialog.prototype.get delegate):
+        (WebInspector.Dialog.prototype.get representedObject):
+        (WebInspector.Dialog.prototype.get cookie):
+        (WebInspector.Dialog.prototype.dismiss):
+        * UserInterface/Models/ResourceQueryResult.js:
+        (WebInspector.ResourceQueryResult):
+        (WebInspector.ResourceQueryResult.prototype.get cookie):
+        Include cookie data along with the represented object in matches
+        and dialog results.
+
+        * UserInterface/Controllers/ResourceQueryController.js:
+        (WebInspector.ResourceQueryController.prototype.executeQuery):
+        Cut off location data from a query, and stash it on the query result.
+        A query can be "<name>:<line>:<column>", and the line/column data
+        becomes cookie data for the resource.
+
+        * UserInterface/Views/OpenResourceDialog.js:
+        (WebInspector.OpenResourceDialog.prototype._populateResourceTreeOutline):
+        If the query is just ":<line>:<column>" have it jump to a location
+        in the current content view if applicable.
+
+        (WebInspector.OpenResourceDialog.prototype._handleKeydownEvent):
+        (WebInspector.OpenResourceDialog.prototype._treeSelectionDidChange):
+        When dismissing, include cookie data.
+
 2016-08-11  Nikita Vasilyev  <[email protected]>
 
         REGRESSION (r204264): Web Inspector: Uncaught Exception in Network tab when reloading a web page

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Main.js (204417 => 204418)


--- trunk/Source/WebInspectorUI/UserInterface/Base/Main.js	2016-08-12 20:03:49 UTC (rev 204417)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Main.js	2016-08-12 20:34:43 UTC (rev 204418)
@@ -1867,7 +1867,7 @@
     return null;
 };
 
-WebInspector._focusedOrVisibleContentView = function()
+WebInspector.focusedOrVisibleContentView = function()
 {
     let focusedContentView = this._focusedContentView();
     if (focusedContentView)
@@ -1919,7 +1919,7 @@
 
 WebInspector._save = function(event)
 {
-    var contentView = this._focusedOrVisibleContentView();
+    var contentView = this.focusedOrVisibleContentView();
     if (!contentView || !contentView.supportsSave)
         return;
 
@@ -1928,7 +1928,7 @@
 
 WebInspector._saveAs = function(event)
 {
-    var contentView = this._focusedOrVisibleContentView();
+    var contentView = this.focusedOrVisibleContentView();
     if (!contentView || !contentView.supportsSave)
         return;
 
@@ -2464,5 +2464,5 @@
     if (!representedObject)
         return;
 
-    WebInspector.showRepresentedObject(representedObject);
+    WebInspector.showRepresentedObject(representedObject, dialog.cookie);
 };

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/ResourceQueryController.js (204417 => 204418)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/ResourceQueryController.js	2016-08-12 20:03:49 UTC (rev 204417)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/ResourceQueryController.js	2016-08-12 20:34:43 UTC (rev 204418)
@@ -56,6 +56,15 @@
 
         query = query.removeWhitespace().toLowerCase();
 
+        let cookie = null;
+        if (query.includes(":")) {
+            let [newQuery, lineNumber, columnNumber] = query.split(":");
+            query = newQuery;
+            lineNumber = lineNumber ? parseInt(lineNumber, 10) - 1 : 0;
+            columnNumber = columnNumber ? parseInt(columnNumber, 10) - 1 : 0;
+            cookie = {lineNumber, columnNumber};
+        }
+
         let results = [];
         for (let [resource, cachedData] of this._resourceDataMap) {
             if (!cachedData.searchString) {
@@ -66,7 +75,7 @@
 
             let matches = this._findQueryMatches(query, cachedData.searchString, cachedData.specialCharacterIndices);
             if (matches.length)
-                results.push(new WebInspector.ResourceQueryResult(resource, matches));
+                results.push(new WebInspector.ResourceQueryResult(resource, matches, cookie));
         }
 
         // Resources are sorted in descending order by rank. Resources of equal

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/ResourceQueryResult.js (204417 => 204418)


--- trunk/Source/WebInspectorUI/UserInterface/Models/ResourceQueryResult.js	2016-08-12 20:03:49 UTC (rev 204417)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/ResourceQueryResult.js	2016-08-12 20:34:43 UTC (rev 204418)
@@ -25,7 +25,7 @@
 
 WebInspector.ResourceQueryResult = class QueryResult extends WebInspector.Object
 {
-    constructor(resource, matches)
+    constructor(resource, matches, cookie)
     {
         console.assert(matches.length, "Query matches list can't be empty.");
 
@@ -33,11 +33,13 @@
 
         this._resource = resource;
         this._matches = matches;
+        this._cookie = cookie || null;
     }
 
     // Public
 
     get resource() { return this._resource; }
+    get cookie() { return this._cookie; }
 
     get rank()
     {

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/Dialog.js (204417 => 204418)


--- trunk/Source/WebInspectorUI/UserInterface/Views/Dialog.js	2016-08-12 20:03:49 UTC (rev 204417)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/Dialog.js	2016-08-12 20:34:43 UTC (rev 204418)
@@ -32,26 +32,17 @@
         this._delegate = delegate;
         this._dismissing = false;
         this._representedObject = null;
+        this._cookie = null;
         this._visible = false;
     }
 
     // Public
 
-    get visible()
-    {
-        return this._visible;
-    }
+    get visible() { return this._visible; }
+    get delegate() { return this._delegate; }
+    get representedObject() { return this._representedObject; }
+    get cookie() { return this._cookie; }
 
-    get delegate()
-    {
-        return this._delegate;
-    }
-
-    get representedObject()
-    {
-        return this._representedObject;
-    }
-
     present(parentElement)
     {
         console.assert(!this.element.parentNode);
@@ -63,7 +54,7 @@
         this.didPresentDialog();
     }
 
-    dismiss(representedObject)
+    dismiss(representedObject, cookie)
     {
         if (this._dismissing)
             return;
@@ -74,6 +65,7 @@
 
         this._dismissing = true;
         this._representedObject = representedObject || null;
+        this._cookie = cookie || null;
         this._visible = false;
 
         this.element.remove();

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/OpenResourceDialog.js (204417 => 204418)


--- trunk/Source/WebInspectorUI/UserInterface/Views/OpenResourceDialog.js	2016-08-12 20:03:49 UTC (rev 204417)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/OpenResourceDialog.js	2016-08-12 20:34:43 UTC (rev 204418)
@@ -110,6 +110,7 @@
                 continue;
 
             treeElement.mainTitle = createHighlightedTitleFragment(resource.displayName, result.matchingTextRanges);
+            treeElement[WebInspector.OpenResourceDialog.ResourceMatchCookieDataSymbol] = result.cookie;
             this._treeOutline.appendChild(treeElement);
         }
 
@@ -150,11 +151,25 @@
             event.preventDefault();
         } else if (event.keyCode === WebInspector.KeyboardShortcut.Key.Enter.keyCode) {
             if (this._treeOutline.selectedTreeElement) {
-                this.dismiss(this._treeOutline.selectedTreeElement.representedObject);
+                this.dismiss(this._treeOutline.selectedTreeElement.representedObject, this._treeOutline.selectedTreeElement[WebInspector.OpenResourceDialog.ResourceMatchCookieDataSymbol]);
                 event.preventDefault();
                 return;
             }
 
+            // ":<line>:<column>" jumps to a location for the current ContentView.
+            if (/^:\d/.test(this._inputElement.value)) {
+                let visibleContentView = WebInspector.focusedOrVisibleContentView();
+                let representedObject = visibleContentView ? visibleContentView.representedObject : null;
+                if (representedObject && representedObject instanceof WebInspector.SourceCode) {
+                    let [, lineNumber, columnNumber] = this._inputElement.value.split(":");
+                    lineNumber = lineNumber ? parseInt(lineNumber, 10) - 1 : 0;
+                    columnNumber = columnNumber ? parseInt(columnNumber, 10) - 1 : 0;
+                    this.dismiss(representedObject, {lineNumber, columnNumber});
+                    event.preventDefault();
+                    return;
+                }
+            }
+
             this._inputElement.select();
         } else if (event.keyCode === WebInspector.KeyboardShortcut.Key.Up.keyCode || event.keyCode === WebInspector.KeyboardShortcut.Key.Down.keyCode) {
             let treeElement = this._treeOutline.selectedTreeElement;
@@ -231,7 +246,7 @@
         if (!event.data.selectedByUser)
             return;
 
-        this.dismiss(treeElement.representedObject);
+        this.dismiss(treeElement.representedObject, treeElement[WebInspector.OpenResourceDialog.ResourceMatchCookieDataSymbol]);
     }
 
     _addResource(resource, suppressFilterUpdate)
@@ -276,3 +291,5 @@
         this._addResource(event.data.resource);
     }
 };
+
+WebInspector.OpenResourceDialog.ResourceMatchCookieDataSymbol = Symbol("open-resource-dialog-resource-match-cookie-data");
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to