aboutsummaryrefslogtreecommitdiff
path: root/ext/js/background/backend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-06-05 13:35:23 -0400
committerGitHub <noreply@github.com>2021-06-05 13:35:23 -0400
commit057283245e2a2ce55f89cacb42067b8c93dd28cd (patch)
tree44fc999d5d82568bde61d83b31f1aab07231377c /ext/js/background/backend.js
parent57fb496fbcd2c31a462c2090e2391594c1ca8215 (diff)
Add support for definitionless main dictionary (#1729)
Diffstat (limited to 'ext/js/background/backend.js')
-rw-r--r--ext/js/background/backend.js22
1 files changed, 17 insertions, 5 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index 42b03c59..33650319 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -411,7 +411,7 @@ class Backend {
async _onApiTermsFind({text, details, optionsContext}) {
const options = this._getProfileOptions(optionsContext);
const {general: {resultOutputMode: mode, maxResults}} = options;
- const findTermsOptions = this._getTranslatorFindTermsOptions(details, options);
+ const findTermsOptions = this._getTranslatorFindTermsOptions(mode, details, options);
const {dictionaryEntries, originalTextLength} = await this._translator.findTerms(mode, text, findTermsOptions);
dictionaryEntries.splice(maxResults);
return {dictionaryEntries, originalTextLength};
@@ -1044,14 +1044,15 @@ class Backend {
async _textParseScanning(text, options) {
const jp = this._japaneseUtil;
const {scanning: {length: scanningLength}, parsing: {readingMode}} = options;
- const findTermsOptions = this._getTranslatorFindTermsOptions({wildcard: null}, options);
+ const mode = 'simple';
+ const findTermsOptions = this._getTranslatorFindTermsOptions(mode, {wildcard: null}, options);
const results = [];
let previousUngroupedSegment = null;
let i = 0;
const ii = text.length;
while (i < ii) {
const {dictionaryEntries, originalTextLength} = await this._translator.findTerms(
- 'simple',
+ mode,
text.substring(i, i + scanningLength),
findTermsOptions
);
@@ -1869,7 +1870,7 @@ class Backend {
this._applyOptions(source);
}
- _getTranslatorFindTermsOptions(details, options) {
+ _getTranslatorFindTermsOptions(mode, details, options) {
const {wildcard} = details;
const enabledDictionaryMap = this._getTranslatorEnabledDictionaryMap(options);
const {
@@ -1886,6 +1887,16 @@ class Backend {
}
} = options;
const textReplacements = this._getTranslatorTextReplacements(textReplacementsOptions);
+ let excludeDictionaryDefinitions = null;
+ if (mode === 'merge' && !enabledDictionaryMap.has(mainDictionary)) {
+ enabledDictionaryMap.set(mainDictionary, {
+ index: enabledDictionaryMap.size,
+ priority: 0,
+ allowSecondarySearches: false
+ });
+ excludeDictionaryDefinitions = new Set();
+ excludeDictionaryDefinitions.add(mainDictionary);
+ }
return {
wildcard,
mainDictionary,
@@ -1897,7 +1908,8 @@ class Backend {
convertKatakanaToHiragana,
collapseEmphaticSequences,
textReplacements,
- enabledDictionaryMap
+ enabledDictionaryMap,
+ excludeDictionaryDefinitions
};
}