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

Make sure JS Code Hints list exact matches first #5716

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 13 additions & 1 deletion src/extensions/default/JavaScriptCodeHints/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,8 @@ define(function (require, exports, module) {
*/
function filterWithQueryAndMatcher(hints, matcher) {
var matchResults = $.map(hints, function (hint) {
var searchResult = matcher.match(hint.value, query);
var searchResult = matcher.match(hint.value, query),
partialHint = "";
if (searchResult) {
searchResult.value = hint.value;
searchResult.guess = hint.guess;
Expand All @@ -577,6 +578,17 @@ define(function (require, exports, module) {
} else {
searchResult.builtin = 0;
}

partialHint = hint.value.substring(0, query.length);

if (partialHint === query) {
// Exact matches gets the highest score possible
// Note: The most negative score is the highest score
searchResult.matchGoodness = -Number.MAX_VALUE;
} else if (partialHint.toLowerCase() === query.toLowerCase()) {
// Case insensitive exact matches get the second highest score
searchResult.matchGoodness = -Number.MAX_VALUE / 10;
}
}

return searchResult;
Expand Down
1 change: 1 addition & 0 deletions src/utils/StringMatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ define(function (require, exports, module) {
} else {
var valueA = a[comparison];
var valueB = b[comparison];

if (typeof valueA === "string") {
valueA = valueA.toLowerCase();
valueB = valueB.toLowerCase();
Expand Down