diff options
Diffstat (limited to 'ext/bg/js/search-query-parser.js')
-rw-r--r-- | ext/bg/js/search-query-parser.js | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/ext/bg/js/search-query-parser.js b/ext/bg/js/search-query-parser.js index 1c89583f..cdface15 100644 --- a/ext/bg/js/search-query-parser.js +++ b/ext/bg/js/search-query-parser.js @@ -24,10 +24,9 @@ * docSentenceExtract */ -class QueryParser extends TextScanner { +class QueryParser { constructor({getOptionsContext, setContent, setSpinnerVisible}) { - super(document.querySelector('#query-parser-content'), () => [], []); - + this._options = null; this.getOptionsContext = getOptionsContext; this.setContent = setContent; this.setSpinnerVisible = setSpinnerVisible; @@ -38,26 +37,34 @@ class QueryParser extends TextScanner { this.queryParserSelect = document.querySelector('#query-parser-select-container'); this.queryParserGenerator = new QueryParserGenerator(); + + this._textScanner = new TextScanner( + this.queryParser, + () => [], + [] + ); + this._textScanner.onSearchSource = this.onSearchSource.bind(this); } async prepare() { await this.queryParserGenerator.prepare(); + this.queryParser.addEventListener('click', this.onClick2.bind(this)); } onClick2(e) { - this.searchAt(e.clientX, e.clientY, 'click'); + this._textScanner.searchAt(e.clientX, e.clientY, 'click'); } async onSearchSource(textSource, cause) { if (textSource === null) { return null; } - const searchText = this.getTextSourceContent(textSource, this.options.scanning.length); + const searchText = this._textScanner.getTextSourceContent(textSource, this._options.scanning.length); if (searchText.length === 0) { return; } const {definitions, length} = await apiTermsFind(searchText, {}, this.getOptionsContext()); if (definitions.length === 0) { return null; } - const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); + const sentence = docSentenceExtract(textSource, this._options.anki.sentenceExt); textSource.setEndOffset(length); @@ -82,16 +89,10 @@ class QueryParser extends TextScanner { }], 'search'); } - getMouseEventListeners() { - return [ - ...super.getMouseEventListeners(), - [this.node, 'click', this.onClick2.bind(this)] - ]; - } - setOptions(options) { - super.setOptions(options); - super.setEnabled(true); + this._options = options; + this._textScanner.setOptions(options); + this._textScanner.setEnabled(true); this.queryParser.dataset.termSpacing = `${options.parsing.termSpacing}`; } @@ -111,7 +112,7 @@ class QueryParser extends TextScanner { } getParseResult() { - const {selectedParser} = this.options.parsing; + const {selectedParser} = this._options.parsing; return this.parseResults.find((r) => r.id === selectedParser); } @@ -142,7 +143,7 @@ class QueryParser extends TextScanner { renderParserSelect() { this.queryParserSelect.textContent = ''; if (this.parseResults.length > 1) { - const {selectedParser} = this.options.parsing; + const {selectedParser} = this._options.parsing; const select = this.queryParserGenerator.createParserSelect(this.parseResults, selectedParser); select.addEventListener('change', this.onParserChange.bind(this)); this.queryParserSelect.appendChild(select); |