aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/document.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-08-31 17:07:41 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-02 11:40:21 -0400
commit548607ea7f45c5f9201f093c56429faf2906b5ad (patch)
tree98d9a90a60b3f42517501629b2706c54e753edb6 /ext/fg/js/document.js
parent3c9f7ba15267f52dd1bf37cd8835e2f7b76819e7 (diff)
Destructure point to {x, y} only once
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 dc2a9b87..1aa6f83b 100644
--- a/ext/fg/js/document.js
+++ b/ext/fg/js/document.js
@@ -87,8 +87,8 @@ function docImposterCreate(element, isTextarea) {
return [imposter, container];
}
-function docRangeFromPoint(point) {
- const element = document.elementFromPoint(point.x, point.y);
+function docRangeFromPoint({x, y}) {
+ const element = document.elementFromPoint(x, y);
let imposter = null;
let imposterContainer = null;
if (element) {
@@ -105,7 +105,7 @@ function docRangeFromPoint(point) {
}
}
- const range = document.caretRangeFromPoint(point.x, point.y);
+ const range = document.caretRangeFromPoint(x, y);
if (range !== null && isPointInRange(point, range)) {
if (imposter !== null) {
docSetImposterStyle(imposterContainer.style, 'z-index', '-2147483646');
@@ -191,7 +191,7 @@ function docSentenceExtract(source, extent) {
};
}
-function isPointInRange(point, range) {
+function isPointInRange(x, y, range) {
// Scan forward
const nodePre = range.endContainer;
const offsetPre = range.endOffset;
@@ -199,7 +199,7 @@ function isPointInRange(point, range) {
const {node, offset} = TextSourceRange.seekForward(range.endContainer, range.endOffset, 1);
range.setEnd(node, offset);
- if (isPointInAnyRect(point, range.getClientRects())) {
+ if (isPointInAnyRect(x, y, range.getClientRects())) {
return true;
}
} finally {
@@ -210,7 +210,7 @@ function isPointInRange(point, range) {
const {node, offset} = TextSourceRange.seekBackward(range.startContainer, range.startOffset, 1);
range.setStart(node, offset);
- if (isPointInAnyRect(point, range.getClientRects())) {
+ if (isPointInAnyRect(x, y, range.getClientRects())) {
// This purposefully leaves the starting offset as modified and sets teh range length to 0.
range.setEnd(node, offset);
return true;
@@ -220,19 +220,19 @@ function isPointInRange(point, range) {
return false;
}
-function isPointInAnyRect(point, rects) {
+function isPointInAnyRect(x, y, rects) {
for (const rect of rects) {
- if (isPointInRect(point, rect)) {
+ if (isPointInRect(x, y, rect)) {
return true;
}
}
return false;
}
-function isPointInRect(point, rect) {
+function isPointInRect(x, y, rect) {
return (
- point.x >= rect.left && point.x < rect.right &&
- point.y >= rect.top && point.y < rect.bottom);
+ x >= rect.left && x < rect.right &&
+ y >= rect.top && y < rect.bottom);
}
if (typeof document.caretRangeFromPoint !== 'function') {