Skip to content

Commit 43869b6

Browse files
committed
test: for StringMatch.codeHintsSort api
1 parent 2cfa4d3 commit 43869b6

3 files changed

Lines changed: 173 additions & 163 deletions

File tree

src/utils/StringMatch.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -900,11 +900,12 @@ define(function (require, exports, module) {
900900
}
901901
let totalResultCount = orderedResults.length;
902902
function _mergeResults(resultArray) {
903-
for(let result of resultArray) {
903+
for(let resultItem of resultArray) {
904904
if(maxResults && totalResultCount >= maxResults) {
905905
break;
906906
}
907-
orderedResults.push(result);
907+
orderedResults.push(resultItem);
908+
totalResultCount++;
908909
}
909910
}
910911

@@ -1086,7 +1087,7 @@ define(function (require, exports, module) {
10861087
*
10871088
* @param {string} query - The search query to match against choices.
10881089
* @param {Array<string>} choices - The list of possible code hints.
1089-
* @param {object} options - An optional object to specify additional search options.
1090+
* @param {object} [options] - An optional object to specify additional search options.
10901091
* @param {number} options.limit - Maximum number of results to return
10911092
* @param {Array<string>} options.boostPrefixList -Optional, Will rank matching items in the choices to top
10921093
* if query starts with the array. EG: on typing b, we have to show background-color
@@ -1099,17 +1100,24 @@ define(function (require, exports, module) {
10991100
function codeHintsSort(query, choices, options) {
11001101
let choice;
11011102
let results = [];
1103+
options = options || {};
11021104
for(let i=0; i<choices.length; i++) {
11031105
choice = choices[i];
11041106
const result = stringMatch(choice, query, codeHintsMatcherOptions);
11051107
if (result) {
11061108
result.sourceIndex = i;
1109+
if(!query){
1110+
delete result.stringRanges; // for empty query like "", we dont want to show any string ranges
1111+
}
11071112
results.push(result);
11081113
}
11091114
}
11101115
basicMatchSort(results);
11111116
results = _codeHintsRelevanceSort(results, query, options.boostPrefixList || [],
11121117
options.limit, options.onlyContiguous);
1118+
if(!query){
1119+
return results;
1120+
}
11131121
for(let result of results) {
11141122
const ranges = _computeMatchingRanges(query, result.label);
11151123
if(ranges){
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{
2+
"query_ab": [
3+
{
4+
"label": "abx",
5+
"matchGoodness": 1.7976931348623157e+308,
6+
"stringRanges": [
7+
{
8+
"text": "ab",
9+
"matched": true
10+
},
11+
{
12+
"text": "x",
13+
"matched": false
14+
}
15+
],
16+
"sourceIndex": 2
17+
},
18+
{
19+
"label": "f:ab",
20+
"stringRanges": [
21+
{
22+
"text": "f:",
23+
"matched": false
24+
},
25+
{
26+
"text": "ab",
27+
"matched": true
28+
}
29+
],
30+
"matchGoodness": 1.7976931348623157e+308,
31+
"sourceIndex": 0
32+
}
33+
],
34+
"query_empty": [
35+
{
36+
"label": "abx",
37+
"matchGoodness": 1.7976931348623157e+308,
38+
"sourceIndex": 2
39+
},
40+
{
41+
"label": "f:ab",
42+
"matchGoodness": 1.7976931348623157e+308,
43+
"sourceIndex": 0
44+
},
45+
{
46+
"label": "zy",
47+
"matchGoodness": 1.7976931348623157e+308,
48+
"sourceIndex": 1
49+
}
50+
],
51+
"result_ab": [
52+
{
53+
"label": "abx",
54+
"matchGoodness": 1.7976931348623157e+308,
55+
"stringRanges": [
56+
{
57+
"text": "ab",
58+
"matched": true
59+
},
60+
{
61+
"text": "x",
62+
"matched": false
63+
}
64+
],
65+
"sourceIndex": 2
66+
},
67+
{
68+
"label": "f:ab",
69+
"stringRanges": [
70+
{
71+
"text": "f:",
72+
"matched": false
73+
},
74+
{
75+
"text": "ab",
76+
"matched": true
77+
}
78+
],
79+
"matchGoodness": 1.7976931348623157e+308,
80+
"sourceIndex": 0
81+
}
82+
],
83+
"result_boost_zy": [
84+
{
85+
"label": "zy",
86+
"matchGoodness": 1.7976931348623157e+308,
87+
"sourceIndex": 1
88+
},
89+
{
90+
"label": "abx",
91+
"matchGoodness": 1.7976931348623157e+308,
92+
"sourceIndex": 2
93+
},
94+
{
95+
"label": "f:ab",
96+
"matchGoodness": 1.7976931348623157e+308,
97+
"sourceIndex": 0
98+
}
99+
]
100+
}

0 commit comments

Comments
 (0)