Skip to content

Commit 7792d88

Browse files
committed
Work around Webkit returning a null rectangle for a zero-size wrapped space
Issue #2775
1 parent e3da5be commit 7792d88

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

lib/codemirror.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,18 +1646,24 @@
16461646

16471647
var rect;
16481648
if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
1649-
while (start && isExtendingChar(prepared.line.text.charAt(mStart + start))) --start;
1650-
while (mStart + end < mEnd && isExtendingChar(prepared.line.text.charAt(mStart + end))) ++end;
1651-
if (ie && ie_version < 9 && start == 0 && end == mEnd - mStart) {
1652-
rect = node.parentNode.getBoundingClientRect();
1653-
} else if (ie && cm.options.lineWrapping) {
1654-
var rects = range(node, start, end).getClientRects();
1655-
if (rects.length)
1656-
rect = rects[bias == "right" ? rects.length - 1 : 0];
1657-
else
1658-
rect = nullRect;
1659-
} else {
1660-
rect = range(node, start, end).getBoundingClientRect() || nullRect;
1649+
for (;;) {
1650+
while (start && isExtendingChar(prepared.line.text.charAt(mStart + start))) --start;
1651+
while (mStart + end < mEnd && isExtendingChar(prepared.line.text.charAt(mStart + end))) ++end;
1652+
if (ie && ie_version < 9 && start == 0 && end == mEnd - mStart) {
1653+
rect = node.parentNode.getBoundingClientRect();
1654+
} else if (ie && cm.options.lineWrapping) {
1655+
var rects = range(node, start, end).getClientRects();
1656+
if (rects.length)
1657+
rect = rects[bias == "right" ? rects.length - 1 : 0];
1658+
else
1659+
rect = nullRect;
1660+
} else {
1661+
rect = range(node, start, end).getBoundingClientRect() || nullRect;
1662+
}
1663+
if (rect.left || rect.right || start == 0) break;
1664+
end = start;
1665+
start = start - 1;
1666+
collapse = "right";
16611667
}
16621668
} else { // If it is a widget, simply get the box for the whole widget.
16631669
if (start > 0) collapse = bias = "right";

0 commit comments

Comments
 (0)