diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-05-08 19:05:50 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-08 19:05:50 -0400 |
commit | 3949db26d778bc3f593438211b148e8309921542 (patch) | |
tree | 7a93fdc9d4a58de8c29acaefa0e5f7eeddd2a5b3 /ext/fg | |
parent | b936c3e4b1bc993e535b02dee91bf6afc15a3564 (diff) |
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
Diffstat (limited to 'ext/fg')
-rw-r--r-- | ext/fg/js/frontend.js | 18 |
1 files changed, 9 insertions, 9 deletions
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; |