Skip to content
Draft
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
8 changes: 8 additions & 0 deletions assets/js/utils/__tests__/local-autocompleter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ describe('LocalAutocompleter', () => {
`);
});

it('should return a suggestion at the start of the index', () => {
expectLocalAutocomplete('artist').toMatchInlineSnapshot(`
[
"{artist}:test (1)",
]
`);
});

it('should return suggestion for an alias', () => {
expectLocalAutocomplete('flowers').toMatchInlineSnapshot(`
[
Expand Down
8 changes: 4 additions & 4 deletions assets/js/utils/local-autocompleter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class LocalAutocompleter {
return strcmp(mapName(this.referenceToName(index, false)).slice(0, prefix.length), prefix);
};

while (min < max - 1) {
while (min < max) {
const med = min + (((max - min) / 2) | 0);
const referenceIndex = mapIndex(med);

Expand All @@ -216,13 +216,13 @@ export class LocalAutocompleter {
max = med;
} else {
// too small, go right
min = med;
min = med + 1;
}
}

// Scan forward until no more matches occur
while (min < this.numTags - 1) {
const referenceIndex = mapIndex(++min);
while (min < this.numTags) {
const referenceIndex = mapIndex(min++);

if (compare(referenceIndex) !== 0) {
break;
Expand Down
Loading