From 6d3037f3d6548b742fa73aec7504c4384f327674 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 14 Sep 2019 14:27:25 -0400 Subject: Remove destructuring from searchAt, containsPoint, docRangeFromPoint --- ext/fg/js/document.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/fg/js/document.js') diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js index 60b1b9bd..f2459197 100644 --- a/ext/fg/js/document.js +++ b/ext/fg/js/document.js @@ -89,7 +89,7 @@ function docImposterCreate(element, isTextarea) { return [imposter, container]; } -function docRangeFromPoint({x, y}, options) { +function docRangeFromPoint(x, y, options) { const elements = document.elementsFromPoint(x, y); let imposter = null; let imposterContainer = null; -- cgit v1.2.3 From 8b1e4d1c6fc5f496c05bb69fe9e6b2cd12c9090b Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 14 Sep 2019 14:52:03 -0400 Subject: Return only single element when deepDomScan is not enabled --- ext/fg/js/document.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'ext/fg/js/document.js') diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js index f2459197..079a5034 100644 --- a/ext/fg/js/document.js +++ b/ext/fg/js/document.js @@ -89,8 +89,18 @@ function docImposterCreate(element, isTextarea) { return [imposter, container]; } +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 elements = document.elementsFromPoint(x, y); + const deepDomScan = options.scanning.deepDomScan; + const elements = docElementsFromPoint(x, y, deepDomScan); let imposter = null; let imposterContainer = null; if (elements.length > 0) { @@ -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'); -- cgit v1.2.3 From 073420a121a0b615989e4b240ca910e7f10d84f3 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 15 Sep 2019 16:09:46 -0400 Subject: Normalize XHTML document node.nodeNode to upper case --- ext/fg/js/document.js | 2 +- ext/fg/js/source.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'ext/fg/js/document.js') diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js index 079a5034..9afc44f0 100644 --- a/ext/fg/js/document.js +++ b/ext/fg/js/document.js @@ -105,7 +105,7 @@ function docRangeFromPoint(x, y, options) { 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); diff --git a/ext/fg/js/source.js b/ext/fg/js/source.js index 18a1a976..4642de50 100644 --- a/ext/fg/js/source.js +++ b/ext/fg/js/source.js @@ -88,7 +88,7 @@ class TextSourceRange { } const skip = ['RT', 'SCRIPT', 'STYLE']; - if (skip.includes(node.nodeName)) { + if (skip.includes(node.nodeName.toUpperCase())) { return false; } @@ -285,7 +285,7 @@ class TextSourceElement { } setEndOffset(length) { - switch (this.element.nodeName) { + switch (this.element.nodeName.toUpperCase()) { case 'BUTTON': this.content = this.element.innerHTML; break; -- cgit v1.2.3 From 02927f9004132114c975b34491ceb28fb764f2f8 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 18 Sep 2019 22:11:18 -0400 Subject: Handle null return value of document.caretPositionFromPoint --- ext/fg/js/document.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ext/fg/js/document.js') diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js index 9afc44f0..94a68e6c 100644 --- a/ext/fg/js/document.js +++ b/ext/fg/js/document.js @@ -267,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; -- cgit v1.2.3