diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-08-31 22:38:01 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-09-02 11:43:49 -0400 |
commit | ee59b3ab8b21d19055302302f28709c6a4e7b918 (patch) | |
tree | 23b6079f081441a513e47fc1515b027bd126e5c3 /ext/fg | |
parent | 171e3f1097a86b993ba1e16c07c4ad6d5bff75ee (diff) |
Reduce amount of isPointInRange calls for repeated ranges
Diffstat (limited to 'ext/fg')
-rw-r--r-- | ext/fg/js/document.js | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js index 727bc5d2..b6e1f83b 100644 --- a/ext/fg/js/document.js +++ b/ext/fg/js/document.js @@ -269,15 +269,19 @@ function caretRangeFromPointExt(x, y, elements) { const modifications = []; try { let i = 0; + let startContinerPre = null; while (true) { const range = caretRangeFromPoint(x, y); if (range === null) { return null; } - const inRange = isPointInRange(x, y, range); - if (inRange) { - return range; + const startContainer = range.startContainer; + if (startContinerPre !== startContainer) { + if (isPointInRange(x, y, range)) { + return range; + } + startContinerPre = startContainer; } i = disableTransparentElement(elements, i, modifications); |