From 3949db26d778bc3f593438211b148e8309921542 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 8 May 2020 19:05:50 -0400 Subject: Text scanner refactor (#517) * Fix return type * Pass search function as a constructor argument * Pass constructor as a details object For consistency with other complex constructors and improved semantics. * Convert _ignorePoints to a single optional function * Organize functions * Rename ignorePoints to ignorePoint --- ext/fg/js/frontend.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'ext/fg/js') diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 9de6597e..78440991 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -39,12 +39,12 @@ class Frontend { this._enabledEventListeners = new EventListenerCollection(); this._activeModifiers = new Set(); this._optionsUpdatePending = false; - this._textScanner = new TextScanner( - window, - () => this._popup.isProxy() ? [] : [this._popup.getContainer()], - [(x, y) => this._popup.containsPoint(x, y)] - ); - this._textScanner.onSearchSource = this._onSearchSource.bind(this); + this._textScanner = new TextScanner({ + node: window, + ignoreElements: () => this._popup.isProxy() ? [] : [this._popup.getContainer()], + ignorePoint: (x, y) => this._popup.containsPoint(x, y), + search: this._search.bind(this) + }); this._windowMessageHandlers = new Map([ ['popupClose', () => this._textScanner.clearSelection(false)], @@ -107,7 +107,7 @@ class Frontend { } async setTextSource(textSource) { - await this._onSearchSource(textSource, 'script'); + await this._search(textSource, 'script'); this._textScanner.setCurrentTextSource(textSource); } @@ -137,7 +137,7 @@ class Frontend { const textSourceCurrent = this._textScanner.getCurrentTextSource(); const causeCurrent = this._textScanner.causeCurrent; if (textSourceCurrent !== null && causeCurrent !== null) { - await this._onSearchSource(textSourceCurrent, causeCurrent); + await this._search(textSourceCurrent, causeCurrent); } } @@ -204,7 +204,7 @@ class Frontend { await this.updateOptions(); } - async _onSearchSource(textSource, cause) { + async _search(textSource, cause) { await this._updatePendingOptions(); let results = null; -- cgit v1.2.3