Skip to content

Commit 0eaf800

Browse files
authored
Merge pull request #118 from JayWearsSocks/sound-of-da-police-name-search
Use displayName for order of tune list, and for search by text
2 parents 9f4f6bc + 9aebb99 commit 0eaf800

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/state/state.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ export function getSongName(state: State, songIdx?: number): string | undefined
326326
return getI18n().t("state.untitled-song", { no });
327327
}
328328

329+
function getTuneSortName(tunes: Record<string, Tune>, name: string): string {
330+
return (tunes[name].displayName ?? name).toLowerCase();
331+
}
332+
329333
export function getSortedTuneList(state: State): Array<string> {
330334
return Object.keys(state.tunes).sort(function(a, b) {
331335
const idx1 = defaultTunes.firstInSorting.indexOf(a);
@@ -338,7 +342,7 @@ export function getSortedTuneList(state: State): Array<string> {
338342
else if(idx2 != -1)
339343
return 1;
340344
else
341-
return a.toLowerCase() < b.toLowerCase() ? -1 : 1;
345+
return getTuneSortName(state.tunes, a) < getTuneSortName(state.tunes, b) ? -1 : 1;
342346
});
343347
}
344348

src/ui/pattern-list-filter.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@
1212
1313
export const DEFAULT_FILTER: Filter = { text: "", cat: "all" };
1414
15+
function textIsInTuneName(state: State, name: string, text: string): boolean {
16+
const tune = state.tunes[name];
17+
const toSearch = [...tune.displayName ? [tune.displayName] : [], name];
18+
return toSearch.some(s => s.toLowerCase().indexOf(text) != -1);
19+
}
20+
1521
export function filterPatternList(state: State, params?: Filter | null): string[] {
1622
params = params || DEFAULT_FILTER;
1723
1824
const ret: string[] = [ ];
1925
const tuneNames = getSortedTuneList(state);
2026
const text = params && params.text.trim().toLowerCase() || "";
2127
for(let i = 0; i < tuneNames.length; i++) {
22-
if(text ? (tuneNames[i].toLowerCase().indexOf(text) != -1) : tuneIsInCategory(state.tunes[tuneNames[i]], params.cat))
28+
if(text ? textIsInTuneName(state, tuneNames[i], text) : tuneIsInCategory(state.tunes[tuneNames[i]], params.cat))
2329
ret.push(tuneNames[i]);
2430
}
2531
return ret;

0 commit comments

Comments
 (0)