aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-05-02 12:47:15 -0400
committerGitHub <noreply@github.com>2020-05-02 12:47:15 -0400
commit08ada6844af424e8ff28e592fc6b9dbc1a9a97eb (patch)
tree1c025f5522b76aa9dbb534b3328f96a5afb9125b /ext/mixed
parentce861ce079f8588b12e7b6d6208dee817b09bafa (diff)
Remove Frontend inheritance (#486)
* Make Frontend use composition instead of inheritance for TextScanner * Use push instead of concat * Update setOptions and setEnabled APIs * Update how onWindowMessage event listener is added/removed * Rename options to _options * Use bind instead of arrow function * Fix selection being cleared due to settings changes
Diffstat (limited to 'ext/mixed')
-rw-r--r--ext/mixed/js/text-scanner.js22
1 files changed, 16 insertions, 6 deletions
diff --git a/ext/mixed/js/text-scanner.js b/ext/mixed/js/text-scanner.js
index c582ccd8..774eef44 100644
--- a/ext/mixed/js/text-scanner.js
+++ b/ext/mixed/js/text-scanner.js
@@ -45,6 +45,16 @@ class TextScanner extends EventDispatcher {
this.preventNextMouseDown = false;
this.preventNextClick = false;
this.preventScroll = false;
+
+ this._canClearSelection = true;
+ }
+
+ get canClearSelection() {
+ return this._canClearSelection;
+ }
+
+ set canClearSelection(value) {
+ this._canClearSelection = value;
}
onMouseOver(e) {
@@ -222,9 +232,9 @@ class TextScanner extends EventDispatcher {
}
}
- setEnabled(enabled, canEnable) {
+ setEnabled(enabled) {
this.eventListeners.removeAllEventListeners();
- this.enabled = enabled && canEnable;
+ this.enabled = enabled;
if (this.enabled) {
this.hookEvents();
} else {
@@ -233,9 +243,9 @@ class TextScanner extends EventDispatcher {
}
hookEvents() {
- let eventListenerInfos = this.getMouseEventListeners();
+ const eventListenerInfos = this.getMouseEventListeners();
if (this.options.scanning.touchInputEnabled) {
- eventListenerInfos = eventListenerInfos.concat(this.getTouchEventListeners());
+ eventListenerInfos.push(...this.getTouchEventListeners());
}
for (const [node, type, listener, options] of eventListenerInfos) {
@@ -264,9 +274,8 @@ class TextScanner extends EventDispatcher {
];
}
- setOptions(options, canEnable=true) {
+ setOptions(options) {
this.options = options;
- this.setEnabled(this.options.general.enable, canEnable);
}
async searchAt(x, y, cause) {
@@ -324,6 +333,7 @@ class TextScanner extends EventDispatcher {
}
clearSelection(passive) {
+ if (!this._canClearSelection) { return; }
if (this.textSourceCurrent !== null) {
if (this.textSourceCurrentSelected) {
this.textSourceCurrent.deselect();