aboutsummaryrefslogtreecommitdiff
path: root/ext/js/language/text-scanner.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2022-10-15 11:40:22 -0400
committerGitHub <noreply@github.com>2022-10-15 11:40:22 -0400
commit5e707248ce4eb595056fd9c46acaf9a0d83678c6 (patch)
tree9f63809bb08abf7111e40dce2e20faefe5b9a08c /ext/js/language/text-scanner.js
parentabb3e5d5d0a63a20933f1770e03e87e756439d35 (diff)
Fix text selection not always working properly (#2246)
Diffstat (limited to 'ext/js/language/text-scanner.js')
-rw-r--r--ext/js/language/text-scanner.js9
1 files changed, 8 insertions, 1 deletions
diff --git a/ext/js/language/text-scanner.js b/ext/js/language/text-scanner.js
index 826c8c5b..fcba47a4 100644
--- a/ext/js/language/text-scanner.js
+++ b/ext/js/language/text-scanner.js
@@ -87,6 +87,7 @@ class TextScanner extends EventDispatcher {
this._canClearSelection = true;
+ this._textSelectionTimer = null;
this._yomichanIsChangingTextSelectionNow = false;
this._userHasNotSelectedAnythingManually = true;
}
@@ -269,7 +270,13 @@ class TextScanner extends EventDispatcher {
if (this._selectText && this._userHasNotSelectedAnythingManually) {
this._yomichanIsChangingTextSelectionNow = true;
this._textSourceCurrent.select();
- setTimeout(() => this._yomichanIsChangingTextSelectionNow = false, 0);
+ if (this._textSelectionTimer !== null) { clearTimeout(this._textSelectionTimer); }
+ // This timeout uses a 50ms delay to ensure that the selectionchange event has time to occur.
+ // If the delay is 0ms, the timeout will sometimes complete before the event.
+ this._textSelectionTimer = setTimeout(() => {
+ this._yomichanIsChangingTextSelectionNow = false;
+ this._textSelectionTimer = null;
+ }, 50);
this._textSourceCurrentSelected = true;
} else {
this._textSourceCurrentSelected = false;