diff --git a/assets/js/utils/local-autocompleter.js b/assets/js/utils/local-autocompleter.js index 7f9a9ee4..44cd2408 100644 --- a/assets/js/utils/local-autocompleter.js +++ b/assets/js/utils/local-autocompleter.js @@ -92,27 +92,26 @@ export class LocalAutocompleter { * Get a Result object as the ith tag inside the file. * * @param {number} i - * @returns {Result} + * @returns {[string, Result]} */ getResultAt(i) { const nameLocation = this.view.getUint32(this.referenceStart + i * 8, true); const imageCount = this.view.getInt32(this.referenceStart + i * 8 + 4, true); + const [ name, associations ] = this.getTagFromLocation(nameLocation); if (imageCount < 0) { // This is actually an alias, so follow it - return this.getResultAt(-imageCount); + return [ name, this.getResultAt(-imageCount)[1] ]; } - const [ name, associations ] = this.getTagFromLocation(nameLocation); - - return { name, imageCount, associations }; + return [ name, { name, imageCount, associations } ]; } /** * Get a Result object as the ith tag inside the file, secondary ordering. * * @param {number} i - * @returns {Result} + * @returns {[string, Result]} */ getSecondaryResultAt(i) { const referenceIndex = this.view.getUint32(this.secondaryStart + i * 4, true); @@ -122,7 +121,7 @@ export class LocalAutocompleter { /** * Perform a binary search to fetch all results matching a condition. * - * @param {(i: number) => Result} getResult + * @param {(i: number) => [string, Result]} getResult * @param {(name: string) => number} compare * @param {{[key: string]: Result}} results */ @@ -136,9 +135,9 @@ export class LocalAutocompleter { while (min < max - 1) { const med = (min + (max - min) / 2) | 0; - const { name } = getResult(med); + const sortKey = getResult(med)[0]; - if (compare(name) >= 0) { + if (compare(sortKey) >= 0) { // too large, go left max = med; } @@ -150,8 +149,8 @@ export class LocalAutocompleter { // Scan forward until no more matches occur while (min < this.numTags - 1) { - const result = getResult(++min); - if (compare(result.name) !== 0) { + const [ sortKey, result ] = getResult(++min); + if (compare(sortKey) !== 0) { break; } diff --git a/lib/philomena/autocomplete.ex b/lib/philomena/autocomplete.ex index 513b4c2d..839a8eed 100644 --- a/lib/philomena/autocomplete.ex +++ b/lib/philomena/autocomplete.ex @@ -65,7 +65,7 @@ defmodule Philomena.Autocomplete do reference_indexes = tags |> Enum.with_index() - |> Enum.map(fn {name, index} -> {name, index} end) + |> Enum.map(fn {{name, _, _, _}, index} -> {name, index} end) |> Map.new() references = @@ -90,7 +90,7 @@ defmodule Philomena.Autocomplete do secondary_references = tags - |> Enum.map(&{name_in_namespace(elem(&1, 0)), &1}) + |> Enum.map(&{name_in_namespace(elem(&1, 0)), elem(&1, 0)}) |> Enum.sort() |> Enum.reduce(<<>>, fn {_k, v}, secondary_references -> target = Map.fetch!(reference_indexes, v)