diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-03-10 20:30:16 -0500 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-03-10 20:30:16 -0500 |
commit | fb1545c1e10532b11d3ed67ee38e768417dd1877 (patch) | |
tree | 85fddfe5639a7bb1d57568be91b02ef19bebc476 /ext/js/language | |
parent | eeac90743d154d4913a0d8784ef94958ee6aea15 (diff) |
Fix sorting of non-top-level definitions (#1516)
Diffstat (limited to 'ext/js/language')
-rw-r--r-- | ext/js/language/translator.js | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js index 56509e39..d93182ee 100644 --- a/ext/js/language/translator.js +++ b/ext/js/language/translator.js @@ -472,7 +472,7 @@ class Translator { glossaryDefinitions.push(glossaryDefinition); } - this._sortDefinitions(glossaryDefinitions); + this._sortDefinitions(glossaryDefinitions, false); const termDetailsList = this._createTermDetailsListFromTermInfoMap(termInfoMap); @@ -582,7 +582,7 @@ class Translator { const results = []; for (const groupDefinitions of groups.values()) { - this._sortDefinitions(groupDefinitions); + this._sortDefinitions(groupDefinitions, false); const definition = this._createGroupedTermDefinition(groupDefinitions); results.push(definition); } @@ -1280,21 +1280,24 @@ class Translator { }); } - _sortDefinitions(definitions) { + _sortDefinitions(definitions, topLevel=true) { if (definitions.length <= 1) { return; } const stringComparer = this._stringComparer; const compareFunction = (v1, v2) => { - // Sort by length of source term - let i = v2.source.length - v1.source.length; - if (i !== 0) { return i; } + let i; + if (topLevel) { + // Sort by length of source term + i = v2.source.length - v1.source.length; + if (i !== 0) { return i; } - // Sort by the number of inflection reasons - i = v1.reasons.length - v2.reasons.length; - if (i !== 0) { return i; } + // Sort by the number of inflection reasons + i = v1.reasons.length - v2.reasons.length; + if (i !== 0) { return i; } - // Sort by how many terms exactly match the source (e.g. for exact kana prioritization) - i = v2.sourceTermExactMatchCount - v1.sourceTermExactMatchCount; - if (i !== 0) { return i; } + // Sort by how many terms exactly match the source (e.g. for exact kana prioritization) + i = v2.sourceTermExactMatchCount - v1.sourceTermExactMatchCount; + if (i !== 0) { return i; } + } // Sort by dictionary priority i = v2.dictionaryOrder.priority - v1.dictionaryOrder.priority; |