diff --git a/src/search/FindBar.js b/src/search/FindBar.js index a68e973b8eb..a5ed36a985b 100644 --- a/src/search/FindBar.js +++ b/src/search/FindBar.js @@ -444,6 +444,7 @@ define(function (require, exports, module) { this.searchField = new QuickSearchField(searchFieldInput, { verticalAdjust: searchFieldInput.offset().top > 0 ? 0 : this._modalBar.getRoot().outerHeight(), maxResults: 20, + firstHighlightIndex: null, resultProvider: function (query) { var asyncResult = new $.Deferred(); asyncResult.resolve(PreferencesManager.getViewState("searchHistory")); diff --git a/src/search/QuickOpen.js b/src/search/QuickOpen.js index 4b1aee9b0da..21255cc5f41 100644 --- a/src/search/QuickOpen.js +++ b/src/search/QuickOpen.js @@ -652,6 +652,7 @@ define(function (require, exports, module) { this.searchField = new QuickSearchField(this.$searchField, { maxResults: 20, + firstHighlightIndex: 0, verticalAdjust: this.modalBar.getRoot().outerHeight(), resultProvider: this._filterCallback, formatter: this._resultsFormatterCallback, diff --git a/src/search/QuickSearchField.js b/src/search/QuickSearchField.js index 224eb46a7fe..81e846c8af8 100644 --- a/src/search/QuickSearchField.js +++ b/src/search/QuickSearchField.js @@ -73,6 +73,8 @@ define(function (require, exports, module) { * Number of pixels to position the popup below where $input is when constructor is called. Useful * if UI is going to animate position after construction, but QuickSearchField may receive input * before the animation is done. + * @param {?number} options.firstHighlightIndex + * Index of the result that is highlighted by default. null to not highlight any result. */ function QuickSearchField($input, options) { this.$input = $input; @@ -91,6 +93,9 @@ define(function (require, exports, module) { $input.on("input", this._handleInput); $input.on("keydown", this._handleKeyDown); + + // For search History this value is set to null + this._firstHighlightIndex = options.firstHighlightIndex; this._dropdownTop = $input.offset().top + $input.height() + (options.verticalAdjust || 0); } @@ -277,7 +282,11 @@ define(function (require, exports, module) { QuickSearchField.prototype._render = function (results, query) { this._displayedQuery = query; this._displayedResults = results; - this._highlightIndex = null; + if (this._firstHighlightIndex >= 0) { + this._highlightIndex = this._firstHighlightIndex; + } else { + this._highlightIndex = null; + } // TODO: fixup to match prev value's item if possible? if (results.error || results.length === 0) { diff --git a/test/spec/QuickSearchField-test.js b/test/spec/QuickSearchField-test.js index 3a77f35d3dd..58d0f75a43a 100644 --- a/test/spec/QuickSearchField-test.js +++ b/test/spec/QuickSearchField-test.js @@ -49,7 +49,8 @@ define(function (require, exports, module) { formatter: function (item) { return "