aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/frontend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-08-22 14:40:44 -0400
committerGitHub <noreply@github.com>2020-08-22 14:40:44 -0400
commit9fa0f2a56a79159227f1f42455157fe9c84132d3 (patch)
treed9a69e94a42939da1d184a3eec8f5ad03ef450ea /ext/fg/js/frontend.js
parentbdb4c21a784a3b5c342bf456a8ed754d6d5e63f2 (diff)
Move findTerms and findKanji functions into TextScanner (#747)
Diffstat (limited to 'ext/fg/js/frontend.js')
-rw-r--r--ext/fg/js/frontend.js35
1 files changed, 6 insertions, 29 deletions
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();