summaryrefslogtreecommitdiff
path: root/ext/fg/js/document.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2019-09-23 17:35:36 -0700
committerAlex Yatskov <alex@foosoft.net>2019-09-23 17:35:36 -0700
commitf4b6527ed6ed1f0f4f5a63b94766b20f3b90e6ec (patch)
tree0d2f733c13597dd4067d3dc01e6da27f96bfe81b /ext/fg/js/document.js
parentcfc6363a01ee00e89866c54709006d6f55d093de (diff)
parentf5afe590ad0730a695614b32032b7ea70b46c7b0 (diff)
Merge branch 'master' into testing
Diffstat (limited to 'ext/fg/js/document.js')
-rw-r--r--ext/fg/js/document.js21
1 files changed, 17 insertions, 4 deletions
diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js
index 60b1b9bd..94a68e6c 100644
--- a/ext/fg/js/document.js
+++ b/ext/fg/js/document.js
@@ -89,13 +89,23 @@ function docImposterCreate(element, isTextarea) {
return [imposter, container];
}
-function docRangeFromPoint({x, y}, options) {
- const elements = document.elementsFromPoint(x, y);
+function docElementsFromPoint(x, y, all) {
+ if (all) {
+ return document.elementsFromPoint(x, y);
+ }
+
+ const e = document.elementFromPoint(x, y);
+ return e !== null ? [e] : [];
+}
+
+function docRangeFromPoint(x, y, options) {
+ const deepDomScan = options.scanning.deepDomScan;
+ const elements = docElementsFromPoint(x, y, deepDomScan);
let imposter = null;
let imposterContainer = null;
if (elements.length > 0) {
const element = elements[0];
- switch (element.nodeName) {
+ switch (element.nodeName.toUpperCase()) {
case 'IMG':
case 'BUTTON':
return new TextSourceElement(element);
@@ -108,7 +118,7 @@ function docRangeFromPoint({x, y}, options) {
}
}
- const range = caretRangeFromPointExt(x, y, options.scanning.deepDomScan ? elements : []);
+ const range = caretRangeFromPointExt(x, y, deepDomScan ? elements : []);
if (range !== null) {
if (imposter !== null) {
docSetImposterStyle(imposterContainer.style, 'z-index', '-2147483646');
@@ -257,6 +267,9 @@ const caretRangeFromPoint = (() => {
// Firefox
return (x, y) => {
const position = document.caretPositionFromPoint(x, y);
+ if (position === null) {
+ return null;
+ }
const node = position.offsetNode;
if (node === null) {
return null;