aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/document.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-08-31 14:57:24 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-08-31 14:57:50 -0400
commitad0dca7bb12d13545b559e9c738fcc0767ba20d5 (patch)
treec3a27f29d185ba06c7fac98f65a54a952d131a2d /ext/fg/js/document.js
parente47e041217708c49032dd3d215eacb23276a1f59 (diff)
Make the imposter element tracked using TextSourceRange
Diffstat (limited to 'ext/fg/js/document.js')
-rw-r--r--ext/fg/js/document.js22
1 files changed, 11 insertions, 11 deletions
diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js
index a017a0a6..e6a16bd5 100644
--- a/ext/fg/js/document.js
+++ b/ext/fg/js/document.js
@@ -70,12 +70,6 @@ function docImposterCreate(element) {
return imposter;
}
-function docImposterDestroy() {
- for (const element of document.getElementsByClassName('yomichan-imposter')) {
- element.parentNode.removeChild(element);
- }
-}
-
function docRangeFromPoint(point) {
const element = document.elementFromPoint(point.x, point.y);
let imposter = null;
@@ -92,12 +86,18 @@ function docRangeFromPoint(point) {
}
const range = document.caretRangeFromPoint(point.x, point.y);
- if (imposter !== null) {
- imposter.style.zIndex = -2147483646;
- imposter.style.pointerEvents = 'none';
+ if (range !== null && isPointInRange(point, range)) {
+ if (imposter !== null) {
+ imposter.style.zIndex = -2147483646;
+ imposter.style.pointerEvents = 'none';
+ }
+ return new TextSourceRange(range, '', imposter);
+ } else {
+ if (imposter !== null) {
+ imposter.parentNode.removeChild(imposter);
+ }
+ return null;
}
-
- return range !== null && isPointInRange(point, range) ? new TextSourceRange(range) : null;
}
function docSentenceExtract(source, extent) {