Commits

Anonymous committed 541733f

Work around weird line wrapping in IE7

  • Participants
  • Parent commits e12d2b8

Comments (0)

Files changed (1)

lib/codemirror.js

       // Include extra text at the end to make sure the measured line is wrapped in the right way.
       if (options.lineWrapping) {
         var end = line.text.indexOf(" ", ch + 2);
-        extra = line.text.slice(ch + 1, end < 0 ? line.text.length : end);
+        extra = line.text.slice(ch + 1, end < 0 ? line.text.length : end + (ie ? 5 : 0));
       }
       measure.innerHTML = "<pre>" + line.getHTML(null, null, false, ch) +
         '<span id="CodeMirror-temp">' + (line.text.charAt(ch) || " ") + "</span>" +
         extra + "</pre>";
-      return document.getElementById("CodeMirror-temp");
+      var elt = document.getElementById("CodeMirror-temp");
+      var top = elt.offsetTop, left = elt.offsetLeft;
+      // Older IEs report zero offsets for spans directly after a wrap
+      if (ie && ch && top == 0 && left == 0) {
+        var backup = document.createElement("span");
+        backup.innerHTML = "x";
+        elt.parentNode.insertBefore(backup, elt.nextSibling);
+        top = backup.offsetTop;
+      }
+      return {top: top, left: left};
     }
     function localCoords(pos, inLineWrap) {
       var x, lh = textHeight(), y = lh * (heightAtLine(doc, pos.line) - (inLineWrap ? displayOffset : 0));
       if (pos.ch == 0) x = 0;
       else {
         var sp = measureLine(getLine(pos.line), pos.ch);
-        x = sp.offsetLeft;
-        if (options.lineWrapping) y += Math.max(0, sp.offsetTop);
+        x = sp.left;
+        if (options.lineWrapping) y += Math.max(0, sp.top);
       }
       return {x: x, y: y, yBot: y + lh};
     }
       function getX(len) {
         var sp = measureLine(lineObj, len);
         if (tw) {
-          var off = Math.round(sp.offsetTop / th);
-          return Math.max(0, sp.offsetLeft + (off - innerOff) * scroller.clientWidth);
+          var off = Math.round(sp.top / th);
+          return Math.max(0, sp.left + (off - innerOff) * scroller.clientWidth);
         }
-        return sp.offsetLeft;
+        return sp.left;
       }
       var from = 0, fromX = 0, to = text.length, toX;
       // Guess a suitable upper bound for our search.