Web Inspector: start searching from the cursor position in the Sources panel.
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Jul 2012 13:08:41 +0000 (13:08 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Jul 2012 13:08:41 +0000 (13:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=90677

Reviewed by Vsevolod Vlasov.

Web Inspector: start searching from the cursor position in the Sources panel.
Drive-by: select whole match upon search cancel.
* inspector/front-end/ScriptsPanel.js:
(WebInspector.ScriptsPanel.prototype.performSearch.finishedCallback):
(WebInspector.ScriptsPanel.prototype.performSearch):
* inspector/front-end/SourceFrame.js:
(WebInspector.SourceFrame.prototype.performSearch.doFindSearchMatches):
(WebInspector.SourceFrame.prototype.performSearch):
* inspector/front-end/TextEditor.js:
(WebInspector.TextEditor.prototype.lastSelection):
(WebInspector.TextEditor.prototype._handleFocused):
* inspector/front-end/TextEditorModel.js:
(WebInspector.TextRange.prototype.serializeToObject):
(WebInspector.TextRange.prototype.compareTo):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@121957 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/ScriptsPanel.js
Source/WebCore/inspector/front-end/SourceFrame.js
Source/WebCore/inspector/front-end/TextEditor.js
Source/WebCore/inspector/front-end/TextEditorModel.js

index 50ea093..84d412b 100644 (file)
@@ -1,3 +1,26 @@
+2012-07-06  Pavel Feldman  <pfeldman@chromium.org>
+
+        Web Inspector: start searching from the cursor position in the Sources panel.
+        https://bugs.webkit.org/show_bug.cgi?id=90677
+
+        Reviewed by Vsevolod Vlasov.
+
+        Web Inspector: start searching from the cursor position in the Sources panel.
+        Drive-by: select whole match upon search cancel.
+
+        * inspector/front-end/ScriptsPanel.js:
+        (WebInspector.ScriptsPanel.prototype.performSearch.finishedCallback):
+        (WebInspector.ScriptsPanel.prototype.performSearch):
+        * inspector/front-end/SourceFrame.js:
+        (WebInspector.SourceFrame.prototype.performSearch.doFindSearchMatches):
+        (WebInspector.SourceFrame.prototype.performSearch):
+        * inspector/front-end/TextEditor.js:
+        (WebInspector.TextEditor.prototype.lastSelection):
+        (WebInspector.TextEditor.prototype._handleFocused):
+        * inspector/front-end/TextEditorModel.js:
+        (WebInspector.TextRange.prototype.serializeToObject):
+        (WebInspector.TextRange.prototype.compareTo):
+
 2012-07-06  Vsevolod Vlasov  <vsevik@chromium.org>
 
         Web Inspector: Snippets should be correctly (re)loaded when inspector is open and on navigation.
index 76765cc..a1481df 100644 (file)
@@ -895,7 +895,7 @@ WebInspector.ScriptsPanel.prototype = {
                 return;
 
             WebInspector.searchController.updateSearchMatchesCount(searchMatches, this);
-            view.jumpToFirstSearchResult();
+            view.jumpToNextSearchResult();
             WebInspector.searchController.updateCurrentMatchIndex(view.currentSearchResultIndex, this);
         }
 
index d939e20..ca0adff 100644 (file)
@@ -330,6 +330,13 @@ WebInspector.SourceFrame.prototype = {
 
             var regex = WebInspector.SourceFrame.createSearchRegex(query);
             this._searchResults = this._collectRegexMatches(regex);
+            var selection = this._textEditor.lastSelection();
+            for (var i = 0; selection && i < this._searchResults.length; ++i) {
+                if (this._searchResults[i].compareTo(selection) > 0) {
+                    this._currentSearchResultIndex = i - 1;
+                    break;
+                }
+            }
 
             callback(this, this._searchResults.length);
         }
index 259639d..8094499 100644 (file)
@@ -393,6 +393,14 @@ WebInspector.TextEditor.prototype = {
     },
 
     /**
+     * @return {WebInspector.TextRange?}
+     */
+    lastSelection: function()
+    {
+        return this._lastSelection;
+    },
+
+    /**
      * @param {WebInspector.TextRange} textRange
      */
     setSelection: function(textRange)
@@ -414,8 +422,9 @@ WebInspector.TextEditor.prototype = {
     {
         // Convert last marked range into a selection upon focus. This is needed to focus the search result.
         if (this._lastMarkedRange) {
-            this._lastSelection = this._lastMarkedRange;
-            delete this._lastMarkedRange; 
+            this.setSelection(this._lastMarkedRange);
+            delete this._lastMarkedRange;
+            return;
         }
 
         if (this._lastSelection) {
index c237a66..55205db 100644 (file)
@@ -109,6 +109,23 @@ WebInspector.TextRange.prototype = {
         serializedTextRange.endLine = this.endLine;
         serializedTextRange.endColumn = this.endColumn;
         return serializedTextRange;
+    },
+
+    /**
+     * @param {WebInspector.TextRange} other
+     * @return {number}
+     */
+    compareTo: function(other)
+    {
+        if (this.startLine > other.startLine)
+            return 1;
+        if (this.startLine < other.startLine)
+            return -1;
+        if (this.startColumn > other.startColumn)
+            return 1;
+        if (this.startColumn < other.startColumn)
+            return -1;
+        return 0;
     }
 }