Title: [120182] trunk
Revision
120182
Author
[email protected]
Date
2012-06-13 04:27:37 -0700 (Wed, 13 Jun 2012)

Log Message

Web Inspector: Make "Go to source and line" possible with "go to file" dialog
https://bugs.webkit.org/show_bug.cgi?id=88740

Reviewed by Vsevolod Vlasov.

Selection dialog now allows search query rewrite and uses line number
suffix to go to a particular line.

* inspector/front-end/FilteredItemSelectionDialog.js:
(WebInspector.FilteredItemSelectionDialog.prototype.onEnter):
(WebInspector.FilteredItemSelectionDialog.prototype._createSearchRegExp):
(WebInspector.SelectionDialogContentProvider.prototype.selectItem):
(WebInspector.SelectionDialogContentProvider.prototype.rewriteQuery):
(WebInspector._javascript_OutlineDialog.prototype.selectItem):
(WebInspector._javascript_OutlineDialog.prototype.rewriteQuery):
(WebInspector.OpenResourceDialog.prototype.selectItem):
(WebInspector.OpenResourceDialog.prototype.rewriteQuery):
* inspector/front-end/ScriptsPanel.js:
(WebInspector.ScriptsPanel.prototype.showUISourceCode):
* inspector/front-end/StylesPanel.js:
(WebInspector.StyleSheetOutlineDialog.prototype.selectItem):
(WebInspector.StyleSheetOutlineDialog.prototype.rewriteQuery):

Modified Paths

Diff

Modified: trunk/LayoutTests/inspector/filtered-item-selection-dialog-filtering.html (120181 => 120182)


--- trunk/LayoutTests/inspector/filtered-item-selection-dialog-filtering.html	2012-06-13 10:48:19 UTC (rev 120181)
+++ trunk/LayoutTests/inspector/filtered-item-selection-dialog-filtering.html	2012-06-13 11:27:37 UTC (rev 120182)
@@ -8,7 +8,7 @@
     function checkQuery(title, query, input)
     {
         var output = [];
-        var regex = WebInspector.FilteredItemSelectionDialog.prototype._createSearchRegExp(query);
+        var regex = WebInspector.FilteredItemSelectionDialog.prototype._innerCreateSearchRegExp(query);
 
         for (var i = 0; i < input.length; ++i) {
             var item = input[i];

Modified: trunk/Source/WebCore/ChangeLog (120181 => 120182)


--- trunk/Source/WebCore/ChangeLog	2012-06-13 10:48:19 UTC (rev 120181)
+++ trunk/Source/WebCore/ChangeLog	2012-06-13 11:27:37 UTC (rev 120182)
@@ -1,3 +1,28 @@
+2012-06-13  Pavel Feldman  <[email protected]>
+
+        Web Inspector: Make "Go to source and line" possible with "go to file" dialog
+        https://bugs.webkit.org/show_bug.cgi?id=88740
+
+        Reviewed by Vsevolod Vlasov.
+
+        Selection dialog now allows search query rewrite and uses line number
+        suffix to go to a particular line.
+
+        * inspector/front-end/FilteredItemSelectionDialog.js:
+        (WebInspector.FilteredItemSelectionDialog.prototype.onEnter):
+        (WebInspector.FilteredItemSelectionDialog.prototype._createSearchRegExp):
+        (WebInspector.SelectionDialogContentProvider.prototype.selectItem):
+        (WebInspector.SelectionDialogContentProvider.prototype.rewriteQuery):
+        (WebInspector._javascript_OutlineDialog.prototype.selectItem):
+        (WebInspector._javascript_OutlineDialog.prototype.rewriteQuery):
+        (WebInspector.OpenResourceDialog.prototype.selectItem):
+        (WebInspector.OpenResourceDialog.prototype.rewriteQuery):
+        * inspector/front-end/ScriptsPanel.js:
+        (WebInspector.ScriptsPanel.prototype.showUISourceCode):
+        * inspector/front-end/StylesPanel.js:
+        (WebInspector.StyleSheetOutlineDialog.prototype.selectItem):
+        (WebInspector.StyleSheetOutlineDialog.prototype.rewriteQuery):
+
 2012-06-12  Hans Wennborg  <[email protected]>
 
         Speech _javascript_ API: Add test for constructing SpeechRecognitionError events

Modified: trunk/Source/WebCore/inspector/front-end/FilteredItemSelectionDialog.js (120181 => 120182)


--- trunk/Source/WebCore/inspector/front-end/FilteredItemSelectionDialog.js	2012-06-13 10:48:19 UTC (rev 120181)
+++ trunk/Source/WebCore/inspector/front-end/FilteredItemSelectionDialog.js	2012-06-13 11:27:37 UTC (rev 120182)
@@ -50,7 +50,6 @@
     styleElement.type = "text/css";
     styleElement.textContent = xhr.responseText;
 
-    this._previousInputLength = 0;
     this._itemElements = [];
     this._elementIndexes = new Map();
     this._elementHighlightChanges = new Map();
@@ -110,7 +109,7 @@
     {
         if (!this._selectedElement)
             return;
-        this._delegate.selectItem(this._elementIndexes.get(this._selectedElement));
+        this._delegate.selectItem(this._elementIndexes.get(this._selectedElement), this._promptElement.value.trim());
     },
 
     /**
@@ -121,20 +120,9 @@
      */
     _itemsLoaded: function(index, chunkLength, chunkIndex, chunkCount)
     {
-        var fragment = document.createDocumentFragment();
-        var candidateItem = this._selectedElement;
-        var regex = this._createSearchRegExp(this._promptElement.value);
-        for (var i = index; i < index + chunkLength; ++i) {
-            var itemElement = this._createItemElement(i, this._delegate.itemTitleAt(i));
-            if (regex.test(this._delegate.itemKeyAt(i))) {
-                if (!candidateItem)
-                    candidateItem = itemElement;
-            } else
-                this._hideItemElement(itemElement);
-            fragment.appendChild(itemElement);
-        }
-        this._itemElementsContainer.appendChild(fragment);
-        this._updateSelection(candidateItem);
+        for (var i = index; i < index + chunkLength; ++i)
+            this._itemElementsContainer.appendChild(this._createItemElement(i, this._delegate.itemTitleAt(i)));
+        this._filterItems();
 
         if (chunkIndex === chunkCount)
             this._progressElement.style.backgroundImage = "";
@@ -156,7 +144,9 @@
 
         var itemElement = document.createElement("div");
         itemElement.className = "item";
-        itemElement.textContent = title;
+        var titleElement = itemElement.createChild("span");
+        var subtitleElement = itemElement.createChild("span");
+        titleElement.textContent = title;
         this._elementIndexes.put(itemElement, index);
         this._itemElements.push(itemElement);
 
@@ -188,30 +178,37 @@
     },
 
     /**
-     * @param {?string} query
+     * @param {string} query
      * @param {boolean=} isGlobal
      */
     _createSearchRegExp: function(query, isGlobal)
     {
-        if (!query || !query.trim())
+        return this._innerCreateSearchRegExp(this._delegate.rewriteQuery(query), isGlobal);
+    },
+
+    /**
+     * @param {?string} query
+     * @param {boolean=} isGlobal
+     */
+    _innerCreateSearchRegExp: function(query, isGlobal)
+    {
+        query = query ? query.trim() : query;
+        if (!query)
             return new RegExp(".*");
 
-        var trimmedQuery = query.trim();
+        var ignoreCase = (query === query.toLowerCase());
 
-        var ignoreCase = (trimmedQuery === trimmedQuery.toLowerCase());
-
         const toEscape = "^[]{}()\\.$*+?|";
 
         var regExpString = "";
-        for (var i = 0; i < trimmedQuery.length; ++i) {
-            var c = trimmedQuery.charAt(i);
+        for (var i = 0; i < query.length; ++i) {
+            var c = query.charAt(i);
             if (toEscape.indexOf(c) !== -1)
                 c = "\\" + c;
             if (i)
                 regExpString += "[^" + c + "]*";
             regExpString += c;
         }
-
         return new RegExp(regExpString, (ignoreCase ? "i" : "") + (isGlobal ? "g" : ""));
     },
 
@@ -220,26 +217,24 @@
         delete this._filterTimer;
 
         var query = this._promptElement.value;
-        var charsAdded = this._previousInputLength < query.length;
-        this._previousInputLength = query.length;
         query = query.trim();
         var regex = this._createSearchRegExp(query);
 
         var firstElement;
         for (var i = 0; i < this._itemElements.length; ++i) {
             var itemElement = this._itemElements[i];
-            
-            if (this._itemElementVisible(itemElement)) { 
-                if (!regex.test(this._delegate.itemKeyAt(i)))
-                    this._hideItemElement(itemElement);
-            } else if (!charsAdded && regex.test(this._delegate.itemKeyAt(i)))
+            itemElement.lastChild.textContent = this._delegate.itemSubtitleAt(i);
+            if (regex.test(this._delegate.itemKeyAt(i))) {
                 this._showItemElement(itemElement);
-            
-            if (!firstElement && this._itemElementVisible(itemElement))
-                firstElement = itemElement;
+                if (!firstElement)
+                    firstElement = itemElement;
+            } else
+                this._hideItemElement(itemElement);
         }
 
-        this._updateSelection(firstElement);
+        if (!this._selectedElement || !this._itemElementVisible(this._selectedElement))
+            this._updateSelection(firstElement);
+
         if (query) {
             this._highlightItems(query);
             this._query = query;
@@ -335,7 +330,7 @@
         if (!itemElement)
             return;
         this._updateSelection(itemElement);
-        this._delegate.selectItem(this._elementIndexes.get(this._selectedElement));
+        this._delegate.selectItem(this._elementIndexes.get(this._selectedElement), this._promptElement.value.trim());
         WebInspector.Dialog.hide();
     },
 
@@ -356,7 +351,7 @@
     },
 
     /**
-     * @param {!string} query
+     * @param {string} query
      */
     _highlightItems: function(query)
     {
@@ -439,6 +434,12 @@
      */
     itemTitleAt: function(itemIndex) { },
 
+    /*
+     * @param {number} itemIndex
+     * @return {string}
+     */
+    itemSubtitleAt: function(itemIndex) { },
+
     /**
      * @param {number} itemIndex
      * @return {string}
@@ -457,10 +458,17 @@
 
     /**
      * @param {number} itemIndex
+     * @param {string} promptValue
      */
-    selectItem: function(itemIndex) { }
-};
+    selectItem: function(itemIndex, promptValue) { },
 
+    /**
+     * @param {string} query
+     * @return {string}
+     */
+    rewriteQuery: function(query) { },
+}
+
 /**
  * @constructor
  * @implements {WebInspector.SelectionDialogContentProvider}
@@ -500,6 +508,15 @@
         return functionItem.name + (functionItem.arguments ? functionItem.arguments : "");
     },
 
+    /*
+     * @param {number} itemIndex
+     * @return {string}
+     */
+    itemSubtitleAt: function(itemIndex)
+    {
+        return "";
+    },
+
     /**
      * @param {number} itemIndex
      * @return {string}
@@ -557,13 +574,23 @@
 
     /**
      * @param {number} itemIndex
+     * @param {string} promptValue
      */
-    selectItem: function(itemIndex)
+    selectItem: function(itemIndex, promptValue)
     {
         var lineNumber = this._functionItems[itemIndex].line;
         if (!isNaN(lineNumber) && lineNumber >= 0)
             this._view.highlightLine(lineNumber);
         this._view.focus();
+    },
+
+    /**
+     * @param {string} query
+     * @return {string}
+     */
+    rewriteQuery: function(query)
+    {
+        return query;
     }
 }
 
@@ -610,6 +637,15 @@
         return this._uiSourceCodes[itemIndex].parsedURL.lastPathComponent;
     },
 
+    /*
+     * @param {number} itemIndex
+     * @return {string}
+     */
+    itemSubtitleAt: function(itemIndex)
+    {
+        return this._queryLineNumber || "";
+    },
+
     /**
      * @param {number} itemIndex
      * @return {string}
@@ -637,10 +673,27 @@
 
     /**
      * @param {number} itemIndex
+     * @param {string} promptValue
      */
-    selectItem: function(itemIndex)
+    selectItem: function(itemIndex, promptValue)
     {
-        this._panel.showUISourceCode(this._uiSourceCodes[itemIndex]);
+        var lineNumberMatch = promptValue.match(/[^:]+\:([\d]*)$/);
+        var lineNumber = lineNumberMatch ? Math.max(parseInt(lineNumberMatch[1], 10) - 1, 0) : 0;
+        this._panel.showUISourceCode(this._uiSourceCodes[itemIndex], lineNumber);
+    },
+
+    /**
+     * @param {string} query
+     * @return {string}
+     */
+    rewriteQuery: function(query)
+    {
+        if (!query)
+            return query;
+        query = query.trim();
+        var lineNumberMatch = query.match(/([^:]+)(\:[\d]*)$/);
+        this._queryLineNumber = lineNumberMatch ? lineNumberMatch[2] : "";
+        return lineNumberMatch ? lineNumberMatch[1] : query;
     }
 }
 

Modified: trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js (120181 => 120182)


--- trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js	2012-06-13 10:48:19 UTC (rev 120181)
+++ trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js	2012-06-13 11:27:37 UTC (rev 120182)
@@ -420,9 +420,13 @@
         this._showSourceLine(uiLocation.uiSourceCode, uiLocation.lineNumber);
     },
 
-    showUISourceCode: function(uiSourceCode)
+    /**
+     * @param {WebInspector.UISourceCode} uiSourceCode
+     * @param {number} lineNumber
+     */
+    showUISourceCode: function(uiSourceCode, lineNumber)
     {
-        this._showSourceLine(uiSourceCode);
+        this._showSourceLine(uiSourceCode, lineNumber);
     },
 
     /**

Modified: trunk/Source/WebCore/inspector/front-end/StylesPanel.js (120181 => 120182)


--- trunk/Source/WebCore/inspector/front-end/StylesPanel.js	2012-06-13 10:48:19 UTC (rev 120181)
+++ trunk/Source/WebCore/inspector/front-end/StylesPanel.js	2012-06-13 11:27:37 UTC (rev 120182)
@@ -248,6 +248,15 @@
         return this._rules[itemIndex].selectorText;
     },
 
+    /*
+     * @param {number} itemIndex
+     * @return {string}
+     */
+    itemSubtitleAt: function(itemIndex)
+    {
+        return "";
+    },
+
     /**
      * @param {number} itemIndex
      * @return {string}
@@ -306,13 +315,23 @@
 
     /**
      * @param {number} itemIndex
+     * @param {string} promptValue
      */
-    selectItem: function(itemIndex)
+    selectItem: function(itemIndex, promptValue)
     {
         var lineNumber = this._rules[itemIndex].sourceLine;
         if (!isNaN(lineNumber) && lineNumber >= 0)
             this._view.highlightLine(lineNumber);
         this._view.focus();
+    },
+
+    /**
+     * @param {string} query
+     * @return {string}
+     */
+    rewriteQuery: function(query)
+    {
+        return query;
     }
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to