From f21d7454b10b8d3524af528b47308cab4cd41a08 Mon Sep 17 00:00:00 2001 From: "pfeldman@chromium.org" Date: Fri, 6 Jul 2012 13:08:41 +0000 Subject: [PATCH] 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): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@121957 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebCore/ChangeLog | 23 ++++++++++++++++++++++ Source/WebCore/inspector/front-end/ScriptsPanel.js | 2 +- Source/WebCore/inspector/front-end/SourceFrame.js | 7 +++++++ Source/WebCore/inspector/front-end/TextEditor.js | 13 ++++++++++-- .../WebCore/inspector/front-end/TextEditorModel.js | 17 ++++++++++++++++ 5 files changed, 59 insertions(+), 3 deletions(-) diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 50ea093..84d412b 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,26 @@ +2012-07-06 Pavel Feldman + + 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 Web Inspector: Snippets should be correctly (re)loaded when inspector is open and on navigation. diff --git a/Source/WebCore/inspector/front-end/ScriptsPanel.js b/Source/WebCore/inspector/front-end/ScriptsPanel.js index 76765cc..a1481df 100644 --- a/Source/WebCore/inspector/front-end/ScriptsPanel.js +++ b/Source/WebCore/inspector/front-end/ScriptsPanel.js @@ -895,7 +895,7 @@ WebInspector.ScriptsPanel.prototype = { return; WebInspector.searchController.updateSearchMatchesCount(searchMatches, this); - view.jumpToFirstSearchResult(); + view.jumpToNextSearchResult(); WebInspector.searchController.updateCurrentMatchIndex(view.currentSearchResultIndex, this); } diff --git a/Source/WebCore/inspector/front-end/SourceFrame.js b/Source/WebCore/inspector/front-end/SourceFrame.js index d939e20..ca0adff 100644 --- a/Source/WebCore/inspector/front-end/SourceFrame.js +++ b/Source/WebCore/inspector/front-end/SourceFrame.js @@ -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); } diff --git a/Source/WebCore/inspector/front-end/TextEditor.js b/Source/WebCore/inspector/front-end/TextEditor.js index 259639d..8094499 100644 --- a/Source/WebCore/inspector/front-end/TextEditor.js +++ b/Source/WebCore/inspector/front-end/TextEditor.js @@ -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) { diff --git a/Source/WebCore/inspector/front-end/TextEditorModel.js b/Source/WebCore/inspector/front-end/TextEditorModel.js index c237a66..55205db 100644 --- a/Source/WebCore/inspector/front-end/TextEditorModel.js +++ b/Source/WebCore/inspector/front-end/TextEditorModel.js @@ -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; } } -- 2.7.4