Fix a bug that returns empty rects from collapsed ranges that have actual rect data
This is a workaround fix for a WebKit bug:
This bug prevented restoring CFI bookmark locations on Safari!
MODIFY
js/views/cfi_navigation_logic.js
js/views/cfi_navigation_logic.js
@@ -103,8 +103,17 @@ var CfiNavigationLogic = function (options) {
} else if (endNode.nodeType === Node.TEXT_NODE) {
range.setEnd(endNode, endOffset ? endOffset : 0);
}
+
+ // Webkit has a bug where collapsed ranges provide an empty rect with getBoundingClientRect()
+ // https://bugs.webkit.org/show_bug.cgi?id=138949
+ // Thankfully it implements getClientRects() properly...
+ // A collapsed text range may still have geometry!
+ if (range.collapsed) {
+ return normalizeRectangle(range.getClientRects()[0], 0, 0);
+ } else {
return normalizeRectangle(range.getBoundingClientRect(), 0, 0);
}
+ }
function getNodeClientRectList(node, visibleContentOffsets) {
visibleContentOffsets = visibleContentOffsets || getVisibleContentOffsets();

Fix a bug that returns empty rects from collapsed ranges that have actual rect data

This is a workaround fix for a WebKit bug: https://bugs.webkit.org/show_bug.cgi?id=138949

This bug prevented restoring CFI bookmark locations on Safari!