aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-11-23 20:31:48 -0500
committerGitHub <noreply@github.com>2020-11-23 20:31:48 -0500
commit068b1eef71ed1167e7e39effa00cda7deb9251f2 (patch)
treea1a593e6cff0009da2829d2803b570a19fa1ac46 /ext/bg/js
parent12e5cec99c64af164ddb56fd8262d98a23205083 (diff)
Text scanner improvements (#1056)
* Only ignore nodes on non-web pages * Fix issue where options might not be assigned on nested frontends * Refactor default TextScanner options * Add option to enable search only on click * Simplify restore state assignment * Update options context passing * Fix empty title * Use TextScanner to scan content inside of Display * Rename ignoreNodes to excludeSelector(s) * Fix options update incorrectly triggering a re-search * Fix copy throwing an error on the search page * Replace _onSearchQueryUpdated with _search * Use include selector instead of exclude selector
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/query-parser.js2
-rw-r--r--ext/bg/js/search.js66
2 files changed, 31 insertions, 37 deletions
diff --git a/ext/bg/js/query-parser.js b/ext/bg/js/query-parser.js
index 16af77b2..d3065188 100644
--- a/ext/bg/js/query-parser.js
+++ b/ext/bg/js/query-parser.js
@@ -34,8 +34,6 @@ class QueryParser extends EventDispatcher {
this._queryParserModeSelect = document.querySelector('#query-parser-mode-select');
this._textScanner = new TextScanner({
node: this._queryParser,
- ignoreElements: () => [],
- ignorePoint: null,
getOptionsContext,
documentUtil,
searchTerms: true,
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index 498f4ade..476370bf 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -62,7 +62,7 @@ class DisplaySearch extends Display {
async prepare() {
await super.prepare();
await this.updateOptions();
- yomichan.on('optionsUpdated', () => this.updateOptions());
+ yomichan.on('optionsUpdated', this._onOptionsUpdated.bind(this));
this.on('contentUpdating', this._onContentUpdating.bind(this));
this.on('modeChange', this._onModeChange.bind(this));
@@ -126,15 +126,6 @@ class DisplaySearch extends Display {
}
}
- async updateOptions() {
- await super.updateOptions();
- if (!this._isPrepared) { return; }
- const query = this._queryInput.value;
- if (query) {
- this._onSearchQueryUpdated(query, false);
- }
- }
-
postProcessQuery(query) {
if (this._wanakanaEnabled) {
try {
@@ -148,6 +139,14 @@ class DisplaySearch extends Display {
// Private
+ async _onOptionsUpdated() {
+ await this.updateOptions();
+ const query = this._queryInput.value;
+ if (query) {
+ this._search(false);
+ }
+ }
+
_onContentUpdating({type, content, source}) {
let animate = false;
let valid = false;
@@ -183,12 +182,12 @@ class DisplaySearch extends Display {
e.preventDefault();
e.stopImmediatePropagation();
this.blurElement(e.currentTarget);
- this._search();
+ this._search(true);
}
_onSearch(e) {
e.preventDefault();
- this._search();
+ this._search(true);
}
_onCopy() {
@@ -197,27 +196,8 @@ class DisplaySearch extends Display {
}
_onExternalSearchUpdate({text, animate=true}) {
- this._onSearchQueryUpdated(text, animate);
- }
-
- _onSearchQueryUpdated(query, animate) {
- const details = {
- focus: false,
- history: false,
- params: {
- query
- },
- state: {
- focusEntry: 0,
- sentence: {text: query, offset: 0},
- url: window.location.href
- },
- content: {
- definitions: null,
- animate
- }
- };
- this.setContent(details);
+ this._queryInput.value = text;
+ this._search(animate);
}
_onWanakanaEnableChange(e) {
@@ -362,9 +342,25 @@ class DisplaySearch extends Display {
});
}
- _search() {
+ _search(animate) {
const query = this._queryInput.value;
- this._onSearchQueryUpdated(query, true);
+ const details = {
+ focus: false,
+ history: false,
+ params: {
+ query
+ },
+ state: {
+ focusEntry: 0,
+ sentence: {text: query, offset: 0},
+ url: window.location.href
+ },
+ content: {
+ definitions: null,
+ animate
+ }
+ };
+ this.setContent(details);
}
_updateSearchHeight() {