aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-08-31 23:44:24 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-02 11:43:49 -0400
commita2139213c85a0b44e8241f00bca909dd200068e8 (patch)
tree52d7c2eaddca4246d6f25ebf9e89c4d6f402b1eb /ext
parentee59b3ab8b21d19055302302f28709c6a4e7b918 (diff)
Fix issue with whitespace ranges
The size of the rects for these ranges will sometimes be excessively large on Firefox, leading to false positives.
Diffstat (limited to 'ext')
-rw-r--r--ext/fg/js/document.js12
1 files changed, 8 insertions, 4 deletions
diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js
index b6e1f83b..fc8000dd 100644
--- a/ext/fg/js/document.js
+++ b/ext/fg/js/document.js
@@ -199,10 +199,10 @@ function isPointInRange(x, y, range) {
const nodePre = range.endContainer;
const offsetPre = range.endOffset;
try {
- const {node, offset} = TextSourceRange.seekForward(range.endContainer, range.endOffset, 1);
+ const {node, offset, content} = TextSourceRange.seekForward(range.endContainer, range.endOffset, 1);
range.setEnd(node, offset);
- if (isPointInAnyRect(x, y, range.getClientRects())) {
+ if (!isWhitespace(content) && isPointInAnyRect(x, y, range.getClientRects())) {
return true;
}
} finally {
@@ -210,10 +210,10 @@ function isPointInRange(x, y, range) {
}
// Scan backward
- const {node, offset} = TextSourceRange.seekBackward(range.startContainer, range.startOffset, 1);
+ const {node, offset, content} = TextSourceRange.seekBackward(range.startContainer, range.startOffset, 1);
range.setStart(node, offset);
- if (isPointInAnyRect(x, y, range.getClientRects())) {
+ if (!isWhitespace(content) && 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;
@@ -223,6 +223,10 @@ function isPointInRange(x, y, range) {
return false;
}
+function isWhitespace(string) {
+ return string.trim().length === 0;
+}
+
function isPointInAnyRect(x, y, rects) {
for (const rect of rects) {
if (isPointInRect(x, y, rect)) {