Destructure point to {x, y} only once

This commit is contained in:
toasted-nutbread 2019-08-31 17:07:41 -04:00
parent 3c9f7ba152
commit 548607ea7f

View File

@ -87,8 +87,8 @@ function docImposterCreate(element, isTextarea) {
return [imposter, container]; return [imposter, container];
} }
function docRangeFromPoint(point) { function docRangeFromPoint({x, y}) {
const element = document.elementFromPoint(point.x, point.y); const element = document.elementFromPoint(x, y);
let imposter = null; let imposter = null;
let imposterContainer = null; let imposterContainer = null;
if (element) { 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 (range !== null && isPointInRange(point, range)) {
if (imposter !== null) { if (imposter !== null) {
docSetImposterStyle(imposterContainer.style, 'z-index', '-2147483646'); 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 // Scan forward
const nodePre = range.endContainer; const nodePre = range.endContainer;
const offsetPre = range.endOffset; const offsetPre = range.endOffset;
@ -199,7 +199,7 @@ function isPointInRange(point, range) {
const {node, offset} = TextSourceRange.seekForward(range.endContainer, range.endOffset, 1); const {node, offset} = TextSourceRange.seekForward(range.endContainer, range.endOffset, 1);
range.setEnd(node, offset); range.setEnd(node, offset);
if (isPointInAnyRect(point, range.getClientRects())) { if (isPointInAnyRect(x, y, range.getClientRects())) {
return true; return true;
} }
} finally { } finally {
@ -210,7 +210,7 @@ function isPointInRange(point, range) {
const {node, offset} = TextSourceRange.seekBackward(range.startContainer, range.startOffset, 1); const {node, offset} = TextSourceRange.seekBackward(range.startContainer, range.startOffset, 1);
range.setStart(node, offset); 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. // This purposefully leaves the starting offset as modified and sets teh range length to 0.
range.setEnd(node, offset); range.setEnd(node, offset);
return true; return true;
@ -220,19 +220,19 @@ function isPointInRange(point, range) {
return false; return false;
} }
function isPointInAnyRect(point, rects) { function isPointInAnyRect(x, y, rects) {
for (const rect of rects) { for (const rect of rects) {
if (isPointInRect(point, rect)) { if (isPointInRect(x, y, rect)) {
return true; return true;
} }
} }
return false; return false;
} }
function isPointInRect(point, rect) { function isPointInRect(x, y, rect) {
return ( return (
point.x >= rect.left && point.x < rect.right && x >= rect.left && x < rect.right &&
point.y >= rect.top && point.y < rect.bottom); y >= rect.top && y < rect.bottom);
} }
if (typeof document.caretRangeFromPoint !== 'function') { if (typeof document.caretRangeFromPoint !== 'function') {