diff options
Diffstat (limited to 'ext/js/display')
-rw-r--r-- | ext/js/display/display.js | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/ext/js/display/display.js b/ext/js/display/display.js index b5dd4ba6..f86d7b8c 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -1215,28 +1215,45 @@ export class Display extends EventDispatcher { * @returns {Promise<import('dictionary').DictionaryEntry[]>} */ async _findDictionaryEntries(isKanji, source, wildcardsEnabled, optionsContext) { + /** @type {import('dictionary').DictionaryEntry[]} */ + let dictionaryEntries = []; + const {findDetails, source: source2} = this._getFindDetails(source, wildcardsEnabled); if (isKanji) { - return await this._application.api.kanjiFind(source, optionsContext); + dictionaryEntries = await this._application.api.kanjiFind(source, optionsContext); + if (dictionaryEntries.length > 0) { return dictionaryEntries; } + + dictionaryEntries = (await this._application.api.termsFind(source2, findDetails, optionsContext)).dictionaryEntries; } else { - /** @type {import('api').FindTermsDetails} */ - const findDetails = {}; - if (wildcardsEnabled) { - const match = /^([*\uff0a]*)([\w\W]*?)([*\uff0a]*)$/.exec(source); - if (match !== null) { - if (match[1]) { - findDetails.matchType = 'suffix'; - findDetails.deinflect = false; - } else if (match[3]) { - findDetails.matchType = 'prefix'; - findDetails.deinflect = false; - } - source = match[2]; + dictionaryEntries = (await this._application.api.termsFind(source2, findDetails, optionsContext)).dictionaryEntries; + if (dictionaryEntries.length > 0) { return dictionaryEntries; } + + dictionaryEntries = await this._application.api.kanjiFind(source, optionsContext); + } + return dictionaryEntries; + } + + /** + * @param {string} source + * @param {boolean} wildcardsEnabled + * @returns {{findDetails: import('api').FindTermsDetails, source: string}} + */ + _getFindDetails(source, wildcardsEnabled) { + /** @type {import('api').FindTermsDetails} */ + const findDetails = {}; + if (wildcardsEnabled) { + const match = /^([*\uff0a]*)([\w\W]*?)([*\uff0a]*)$/.exec(source); + if (match !== null) { + if (match[1]) { + findDetails.matchType = 'suffix'; + findDetails.deinflect = false; + } else if (match[3]) { + findDetails.matchType = 'prefix'; + findDetails.deinflect = false; } + source = match[2]; } - - const {dictionaryEntries} = await this._application.api.termsFind(source, findDetails, optionsContext); - return dictionaryEntries; } + return {findDetails, source}; } /** |