Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 038bcb6

Browse files
saurabh95Marcel Gerber
authored andcommitted
Add option for first highlight index in Quick Open and Search History (#13444)
* Fixed #13437 * minor change * Passed first highlight index as paramater to QuickSearchField * Added jsdocs
1 parent f4dd55c commit 038bcb6

4 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/search/FindBar.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ define(function (require, exports, module) {
444444
this.searchField = new QuickSearchField(searchFieldInput, {
445445
verticalAdjust: searchFieldInput.offset().top > 0 ? 0 : this._modalBar.getRoot().outerHeight(),
446446
maxResults: 20,
447+
firstHighlightIndex: null,
447448
resultProvider: function (query) {
448449
var asyncResult = new $.Deferred();
449450
asyncResult.resolve(PreferencesManager.getViewState("searchHistory"));

src/search/QuickOpen.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ define(function (require, exports, module) {
652652

653653
this.searchField = new QuickSearchField(this.$searchField, {
654654
maxResults: 20,
655+
firstHighlightIndex: 0,
655656
verticalAdjust: this.modalBar.getRoot().outerHeight(),
656657
resultProvider: this._filterCallback,
657658
formatter: this._resultsFormatterCallback,

src/search/QuickSearchField.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ define(function (require, exports, module) {
7373
* Number of pixels to position the popup below where $input is when constructor is called. Useful
7474
* if UI is going to animate position after construction, but QuickSearchField may receive input
7575
* before the animation is done.
76+
* @param {?number} options.firstHighlightIndex
77+
* Index of the result that is highlighted by default. null to not highlight any result.
7678
*/
7779
function QuickSearchField($input, options) {
7880
this.$input = $input;
@@ -91,6 +93,9 @@ define(function (require, exports, module) {
9193

9294
$input.on("input", this._handleInput);
9395
$input.on("keydown", this._handleKeyDown);
96+
97+
// For search History this value is set to null
98+
this._firstHighlightIndex = options.firstHighlightIndex;
9499

95100
this._dropdownTop = $input.offset().top + $input.height() + (options.verticalAdjust || 0);
96101
}
@@ -277,7 +282,11 @@ define(function (require, exports, module) {
277282
QuickSearchField.prototype._render = function (results, query) {
278283
this._displayedQuery = query;
279284
this._displayedResults = results;
280-
this._highlightIndex = null;
285+
if (this._firstHighlightIndex >= 0) {
286+
this._highlightIndex = this._firstHighlightIndex;
287+
} else {
288+
this._highlightIndex = null;
289+
}
281290
// TODO: fixup to match prev value's item if possible?
282291

283292
if (results.error || results.length === 0) {

test/spec/QuickSearchField-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ define(function (require, exports, module) {
4949
formatter: function (item) { return "<li>" + item + "</li>"; },
5050
resultProvider: function (query) { return provider(query); },
5151
onCommit: function (item, query) { return onCommit(item, query); },
52-
onHighlight: jasmine.createSpy()
52+
onHighlight: jasmine.createSpy(),
53+
firstHighlightIndex: 0
5354
};
5455
searchField = new QuickSearchField($mockInput, options);
5556

0 commit comments

Comments
 (0)