diff options
author | Alex Yatskov <alex@foosoft.net> | 2020-01-26 11:29:30 -0800 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2020-01-26 11:29:30 -0800 |
commit | 0c5b9b1fa1599cbf769d96cdebc226310f9dd8bc (patch) | |
tree | e734e2c3005078dbc248b541d357a934baa8a116 /ext/fg/js/document.js | |
parent | 2a12036ca305044291f1f4105d6a8d249848b210 (diff) | |
parent | 0cf1cf3aa094585bd6db8db2c1f229ba0ea37b6e (diff) |
Merge branch 'master' into testing
Diffstat (limited to 'ext/fg/js/document.js')
-rw-r--r-- | ext/fg/js/document.js | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js index e068e3ba..71654b29 100644 --- a/ext/fg/js/document.js +++ b/ext/fg/js/document.js @@ -110,6 +110,7 @@ function docRangeFromPoint(x, y, deepDomScan) { const elements = docElementsFromPoint(x, y, deepDomScan); let imposter = null; let imposterContainer = null; + let imposterSourceElement = null; if (elements.length > 0) { const element = elements[0]; switch (element.nodeName.toUpperCase()) { @@ -117,9 +118,11 @@ function docRangeFromPoint(x, y, deepDomScan) { case 'BUTTON': return new TextSourceElement(element); case 'INPUT': + imposterSourceElement = element; [imposter, imposterContainer] = docImposterCreate(element, false); break; case 'TEXTAREA': + imposterSourceElement = element; [imposter, imposterContainer] = docImposterCreate(element, true); break; } @@ -131,7 +134,7 @@ function docRangeFromPoint(x, y, deepDomScan) { docSetImposterStyle(imposterContainer.style, 'z-index', '-2147483646'); docSetImposterStyle(imposter.style, 'pointer-events', 'none'); } - return new TextSourceRange(range, '', imposterContainer); + return new TextSourceRange(range, '', imposterContainer, imposterSourceElement); } else { if (imposterContainer !== null) { imposterContainer.parentNode.removeChild(imposterContainer); @@ -269,8 +272,14 @@ const caretRangeFromPoint = (() => { const range = document.createRange(); const offset = (node.nodeType === Node.TEXT_NODE ? position.offset : 0); - range.setStart(node, offset); - range.setEnd(node, offset); + try { + range.setStart(node, offset); + range.setEnd(node, offset); + } catch (e) { + // Firefox throws new DOMException("The operation is insecure.") + // when trying to select a node from within a ShadowRoot. + return null; + } return range; }; } |