Skip to content

Commit

Permalink
Patch for CodeMirror
Browse files Browse the repository at this point in the history
  • Loading branch information
gnestor committed Jan 24, 2017
1 parent d58d766 commit 9d6baf0
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions notebook/static/components/codemirror/lib/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -2464,15 +2464,16 @@ function nodeAndOffsetInLineMap(map, ch, bias) {
return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd}
}

function getUsefulRect(rects, bias) {
var rect = nullRect
if (bias == "left") { for (var i = 0; i < rects.length; i++) {
if ((rect = rects[i]).left != rect.right) { break }
} } else { for (var i$1 = rects.length - 1; i$1 >= 0; i$1--) {
if ((rect = rects[i$1]).left != rect.right) { break }
} }
return rect
}
// Patch for https://github.com/codemirror/CodeMirror/issues/4454
// function getUsefulRect(rects, bias) {
// var rect = nullRect
// if (bias == "left") { for (var i = 0; i < rects.length; i++) {
// if ((rect = rects[i]).left != rect.right) { break }
// } } else { for (var i$1 = rects.length - 1; i$1 >= 0; i$1--) {
// if ((rect = rects[i$1]).left != rect.right) { break }
// } }
// return rect
// }

function measureCharInner(cm, prepared, ch, bias) {
var place = nodeAndOffsetInLineMap(prepared.map, ch, bias)
Expand All @@ -2483,10 +2484,22 @@ function measureCharInner(cm, prepared, ch, bias) {
for (var i$1 = 0; i$1 < 4; i$1++) { // Retry a maximum of 4 times when nonsense rectangles are returned
while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) { --start }
while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) { ++end }
if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart)
{ rect = node.parentNode.getBoundingClientRect() }
else
{ rect = getUsefulRect(range(node, start, end).getClientRects(), bias) }
// Patch for https://github.com/codemirror/CodeMirror/issues/4454
// if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart)
// { rect = node.parentNode.getBoundingClientRect() }
// else
// { rect = getUsefulRect(range(node, start, end).getClientRects(), bias) }
if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart) {
rect = node.parentNode.getBoundingClientRect();
} else if (ie && cm.options.lineWrapping) {
var rects = range(node, start, end).getClientRects();
if (rects.length)
rect = rects[bias == "right" ? rects.length - 1 : 0];
else
rect = nullRect;
} else {
rect = range(node, start, end).getBoundingClientRect() || nullRect;
}
if (rect.left || rect.right || start == 0) { break }
end = start
start = start - 1
Expand Down

0 comments on commit 9d6baf0

Please sign in to comment.