From f58b4962f124d8cba5378b77040ac7962a9c20a5 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 28 Mar 2021 16:04:55 -0400 Subject: [PATCH] Remove repeated disambiguations (#1572) --- ext/js/language/dictionary-data-util.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ext/js/language/dictionary-data-util.js b/ext/js/language/dictionary-data-util.js index f44b81c5..3f096b02 100644 --- a/ext/js/language/dictionary-data-util.js +++ b/ext/js/language/dictionary-data-util.js @@ -172,8 +172,19 @@ class DictionaryDataUtil { } const disambiguations = []; - if (!this._areSetsEqual(terms, allTermsSet)) { disambiguations.push(...this._getSetIntersection(terms, allTermsSet)); } - if (!this._areSetsEqual(readings, allReadingsSet)) { disambiguations.push(...this._getSetIntersection(readings, allReadingsSet)); } + const addTerms = !this._areSetsEqual(terms, allTermsSet); + const addReadings = !this._areSetsEqual(readings, allReadingsSet); + if (addTerms) { + disambiguations.push(...this._getSetIntersection(terms, allTermsSet)); + } + if (addReadings) { + if (addTerms) { + for (const term of terms) { + readings.delete(term); + } + } + disambiguations.push(...this._getSetIntersection(readings, allReadingsSet)); + } return disambiguations; }