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

Add option for first highlight index in Quick Open and Search History #13444

Merged
merged 4 commits into from
Jun 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/search/FindBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
1 change: 1 addition & 0 deletions src/search/QuickOpen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 10 additions & 1 deletion src/search/QuickSearchField.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion test/spec/QuickSearchField-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ define(function (require, exports, module) {
formatter: function (item) { return "<li>" + item + "</li>"; },
resultProvider: function (query) { return provider(query); },
onCommit: function (item, query) { return onCommit(item, query); },
onHighlight: jasmine.createSpy()
onHighlight: jasmine.createSpy(),
firstHighlightIndex: 0
};
searchField = new QuickSearchField($mockInput, options);

Expand Down