From e24075e1a91ab8b58bb5836cf7abcefae5cbf8c3 Mon Sep 17 00:00:00 2001 From: James Maa Date: Mon, 10 Jun 2024 10:59:54 -0700 Subject: Add context menu interface for Yomitan (#1028) * --wip-- [skip ci] * Draft * Remove weird code * Use existing API instead of dulpicating * Small improvements * remove console.log * remove console.log * Add setting for contextMenu * Fix test * Address comments * Add option-util upgrade * fix option-utils --- ext/js/language/text-scanner.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'ext/js/language/text-scanner.js') diff --git a/ext/js/language/text-scanner.js b/ext/js/language/text-scanner.js index aba44644..fdc33400 100644 --- a/ext/js/language/text-scanner.js +++ b/ext/js/language/text-scanner.js @@ -411,10 +411,11 @@ export class TextScanner extends EventDispatcher { /** * @param {import('text-source').TextSource} textSource * @param {import('text-scanner').InputInfoDetail} [inputDetail] + * @param {boolean} showEmpty */ - async search(textSource, inputDetail) { + async search(textSource, inputDetail, showEmpty = false) { const inputInfo = this._createInputInfo(null, 'script', 'script', true, [], [], inputDetail); - await this._search(textSource, this._searchTerms, this._searchKanji, inputInfo); + await this._search(textSource, this._searchTerms, this._searchKanji, inputInfo, showEmpty); } // Private @@ -437,8 +438,9 @@ export class TextScanner extends EventDispatcher { * @param {boolean} searchTerms * @param {boolean} searchKanji * @param {import('text-scanner').InputInfo} inputInfo + * @param {boolean} showEmpty shows a "No results found" popup if no results are found */ - async _search(textSource, searchTerms, searchKanji, inputInfo) { + async _search(textSource, searchTerms, searchKanji, inputInfo, showEmpty = false) { try { const inputInfoDetail = inputInfo.detail; const selectionRestoreInfo = ( @@ -465,7 +467,8 @@ export class TextScanner extends EventDispatcher { const result = await this._findDictionaryEntries(textSource, searchTerms, searchKanji, optionsContext); if (result !== null) { ({dictionaryEntries, sentence, type} = result); - } else if (textSource !== null && textSource instanceof TextSourceElement && await this._isTextLookupWorthy(textSource.fullContent)) { + } else if (showEmpty || (textSource !== null && textSource instanceof TextSourceElement && await this._isTextLookupWorthy(textSource.fullContent))) { + // Shows a "No results found" message dictionaryEntries = []; sentence = {text: '', offset: 0}; } -- cgit v1.2.3