From 9fa0f2a56a79159227f1f42455157fe9c84132d3 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 22 Aug 2020 14:40:44 -0400 Subject: Move findTerms and findKanji functions into TextScanner (#747) --- ext/fg/js/frontend.js | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) (limited to 'ext/fg/js') diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 9e3b902f..981852db 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -253,7 +253,10 @@ class Frontend { modifier: scanningOptions.modifier, useMiddleMouse: scanningOptions.middleMouse, delay: scanningOptions.delay, - touchInputEnabled: scanningOptions.touchInputEnabled + touchInputEnabled: scanningOptions.touchInputEnabled, + scanLength: scanningOptions.length, + sentenceExtent: options.anki.sentenceExt, + layoutAwareScan: scanningOptions.layoutAwareScan }); this._updateTextScannerEnabled(); @@ -399,8 +402,8 @@ class Frontend { if (textSource !== null) { const optionsContext = await this.getOptionsContext(); results = ( - await this._findTerms(textSource, optionsContext) || - await this._findKanji(textSource, optionsContext) + await this._textScanner.findTerms(textSource, optionsContext) || + await this._textScanner.findKanji(textSource, optionsContext) ); if (results !== null) { const focus = (cause === 'mouse'); @@ -424,32 +427,6 @@ class Frontend { return results; } - async _findTerms(textSource, optionsContext) { - const {length: scanLength, layoutAwareScan} = this._options.scanning; - const searchText = this._textScanner.getTextSourceContent(textSource, scanLength, layoutAwareScan); - if (searchText.length === 0) { return null; } - - const {definitions, length} = await api.termsFind(searchText, {}, optionsContext); - if (definitions.length === 0) { return null; } - - textSource.setEndOffset(length, layoutAwareScan); - - return {definitions, type: 'terms'}; - } - - async _findKanji(textSource, optionsContext) { - const layoutAwareScan = this._options.scanning.layoutAwareScan; - const searchText = this._textScanner.getTextSourceContent(textSource, 1, layoutAwareScan); - if (searchText.length === 0) { return null; } - - const definitions = await api.kanjiFind(searchText, optionsContext); - if (definitions.length === 0) { return null; } - - textSource.setEndOffset(1, layoutAwareScan); - - return {definitions, type: 'kanji'}; - } - async _showExtensionUnloaded(textSource) { if (textSource === null) { textSource = this._textScanner.getCurrentTextSource(); -- cgit v1.2.3