aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-11-01 21:24:35 -0500
committerGitHub <noreply@github.com>2020-11-01 21:24:35 -0500
commita8ff38eec31c1055f88f45ea303fe3ae66d43f10 (patch)
treeaa4b905ca588345d719d6c7715a489cb6c64ec3e /ext/mixed/js
parent8ffae565c6feac1c898d8f02f47fe0362cc458e8 (diff)
Fix display issues (#984)
* Remove unused function * Update expresionMulti detection * Simplify kanji early escape * Simplify frequency/pitch data creation * Update implementation of _buildTermMeta * Update how pitch accents sources are collected * Remove old _buildTermMeta
Diffstat (limited to 'ext/mixed/js')
-rw-r--r--ext/mixed/js/dictionary-data-util.js9
-rw-r--r--ext/mixed/js/display-generator.js51
2 files changed, 5 insertions, 55 deletions
diff --git a/ext/mixed/js/dictionary-data-util.js b/ext/mixed/js/dictionary-data-util.js
index 72c28172..709f4ead 100644
--- a/ext/mixed/js/dictionary-data-util.js
+++ b/ext/mixed/js/dictionary-data-util.js
@@ -17,16 +17,13 @@
class DictionaryDataUtil {
static getPitchAccentInfos(definition) {
- if (typeof definition.character === 'string') {
- // Kanji
- return [];
- }
+ const {type} = definition;
+ if (type === 'kanji') { return []; }
const results = new Map();
const allExpressions = new Set();
const allReadings = new Set();
- const expressions = definition.expressions;
- const sources = Array.isArray(expressions) ? expressions : [definition];
+ const sources = [definition];
for (const {pitches: expressionPitches, expression} of sources) {
allExpressions.add(expression);
diff --git a/ext/mixed/js/display-generator.js b/ext/mixed/js/display-generator.js
index 7f8235e2..926eb25d 100644
--- a/ext/mixed/js/display-generator.js
+++ b/ext/mixed/js/display-generator.js
@@ -45,12 +45,12 @@ class DisplayGenerator {
const debugInfoContainer = node.querySelector('.debug-info');
const bodyContainer = node.querySelector('.term-entry-body');
- const {termTags, expressions, definitions} = details;
+ const {termTags, expressions, definitions, type} = details;
const pitches = DictionaryDataUtil.getPitchAccentInfos(details);
const pitchCount = pitches.reduce((i, v) => i + v.pitches.length, 0);
- const expressionMulti = Array.isArray(expressions);
+ const expressionMulti = (type === 'termMerged' || type === 'termMergedByGlossary');
const definitionMulti = Array.isArray(definitions);
const expressionCount = expressionMulti ? expressions.length : 1;
const definitionCount = definitionMulti ? definitions.length : 1;
@@ -568,51 +568,4 @@ class DisplayGenerator {
container.appendChild(document.createTextNode(parts[i]));
}
}
-
- _getPitchInfos(definition) {
- const results = new Map();
-
- const allExpressions = new Set();
- const allReadings = new Set();
- const expressions = definition.expressions;
- const sources = Array.isArray(expressions) ? expressions : [definition];
- for (const {pitches: expressionPitches, expression} of sources) {
- allExpressions.add(expression);
- for (const {reading, pitches, dictionary} of expressionPitches) {
- allReadings.add(reading);
- let dictionaryResults = results.get(dictionary);
- if (typeof dictionaryResults === 'undefined') {
- dictionaryResults = [];
- results.set(dictionary, dictionaryResults);
- }
-
- for (const {position, tags} of pitches) {
- let pitchInfo = this._findExistingPitchInfo(reading, position, tags, dictionaryResults);
- if (pitchInfo === null) {
- pitchInfo = {expressions: new Set(), reading, position, tags};
- dictionaryResults.push(pitchInfo);
- }
- pitchInfo.expressions.add(expression);
- }
- }
- }
-
- for (const dictionaryResults of results.values()) {
- for (const result of dictionaryResults) {
- const exclusiveExpressions = [];
- const exclusiveReadings = [];
- const resultExpressions = result.expressions;
- if (!areSetsEqual(resultExpressions, allExpressions)) {
- exclusiveExpressions.push(...getSetIntersection(resultExpressions, allExpressions));
- }
- if (allReadings.size > 1) {
- exclusiveReadings.push(result.reading);
- }
- result.exclusiveExpressions = exclusiveExpressions;
- result.exclusiveReadings = exclusiveReadings;
- }
- }
-
- return [...results.entries()];
- }
}