Skip to content

Commit 9e5599d

Browse files
committed
Add a kludge to work around poor dimension measurements in bidi text in IE
Closes #1129
1 parent 7db06ab commit 9e5599d

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

lib/codemirror.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,9 @@ window.CodeMirror = (function() {
10221022
}
10231023
}
10241024
if (j == vranges.length) vranges.push(top, bot);
1025-
data[i] = {left: size.left - outer.left, right: size.right - outer.left, top: j};
1025+
var right = size.right;
1026+
if (cur.measureRight) right = getRect(cur.measureRight).left;
1027+
data[i] = {left: size.left - outer.left, right: right - outer.left, top: j};
10261028
}
10271029
for (var i = 0, cur; i < data.length; ++i) if (cur = data[i]) {
10281030
var vr = cur.top;
@@ -1085,10 +1087,9 @@ window.CodeMirror = (function() {
10851087
if (part.from < ch && part.to > ch) return get(ch, rtl);
10861088
var left = rtl ? part.to : part.from, right = rtl ? part.from : part.to;
10871089
if (left == ch) {
1088-
// Opera and IE return bogus offsets and widths for edges
1089-
// where the direction flips, but only for the side with the
1090-
// lower level. So we try to use the side with the higher
1091-
// level.
1090+
// IE returns bogus offsets and widths for edges where the
1091+
// direction flips, but only for the side with the lower
1092+
// level. So we try to use the side with the higher level.
10921093
if (i && part.level < (nb = order[i-1]).level) here = get(nb.level % 2 ? nb.from : nb.to - 1, true);
10931094
else here = get(rtl && part.from != part.to ? ch - 1 : ch);
10941095
if (rtl == linedir) main = here; else other = here;
@@ -3971,6 +3972,21 @@ window.CodeMirror = (function() {
39713972
if (!builder.pre.firstChild && !lineIsHidden(cm.doc, realLine))
39723973
builder.pre.appendChild(document.createTextNode("\u00a0"));
39733974

3975+
var order;
3976+
// Work around problem with the reported dimensions of single-char
3977+
// direction spans on IE (issue #1129). See also the comment in
3978+
// cursorCoords.
3979+
if (measure && ie && (order = getOrder(line))) {
3980+
var l = order.length - 1;
3981+
if (order[l].from == order[l].to) --l;
3982+
var last = order[l], prev = order[l - 1];
3983+
if (last.from + 1 == last.to && prev && last.level < prev.level) {
3984+
var span = measure[builder.pos - 1];
3985+
if (span) span.parentNode.insertBefore(span.measureRight = zeroWidthElement(cm.display.measure),
3986+
span.nextSibling);
3987+
}
3988+
}
3989+
39743990
return builder.pre;
39753991
}
39763992

test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ testCM("verticalMovementCommandsWrapping", function(cm) {
984984

985985
testCM("rtlMovement", function(cm) {
986986
forEach(["خحج", "خحabcخحج", "abخحخحجcd", "abخde", "abخح2342خ1حج", "خ1ح2خح3حxج",
987-
"خحcd", "1خحcd", "abcdeح1ج", "خمرحبها مها!"], function(line) {
987+
"خحcd", "1خحcd", "abcdeح1ج", "خمرحبها مها!", "foobarر"], function(line) {
988988
var inv = line.charAt(0) == "خ";
989989
cm.setValue(line + "\n"); cm.execCommand(inv ? "goLineEnd" : "goLineStart");
990990
var cursor = byClassName(cm.getWrapperElement(), "CodeMirror-cursor")[0];

0 commit comments

Comments
 (0)