MCPcopy
hub / github.com/nwutils/nw-sample-apps / measureLine

Function measureLine

mini-code-edit/cm/lib/codemirror.js:1579–1594  ·  view source on GitHub ↗
(line, ch)

Source from the content-addressed store, hash-verified

1577
1578 var tempId = "CodeMirror-temp-" + Math.floor(Math.random() * 0xffffff).toString(16);
1579 function measureLine(line, ch) {
1580 if (ch == 0) return {top: 0, left: 0};
1581 var wbr = options.lineWrapping && ch < line.text.length &&
1582 spanAffectsWrapping.test(line.text.slice(ch - 1, ch + 1));
1583 measure.innerHTML = "<pre>" + line.getHTML(makeTab, ch, tempId, wbr) + "</pre>";
1584 var elt = document.getElementById(tempId);
1585 var top = elt.offsetTop, left = elt.offsetLeft;
1586 // Older IEs report zero offsets for spans directly after a wrap
1587 if (ie && top == 0 && left == 0) {
1588 var backup = document.createElement("span");
1589 backup.innerHTML = "x";
1590 elt.parentNode.insertBefore(backup, elt.nextSibling);
1591 top = backup.offsetTop;
1592 }
1593 return {top: top, left: left};
1594 }
1595 function localCoords(pos, inLineWrap) {
1596 var x, lh = textHeight(), y = lh * (heightAtLine(doc, pos.line) - (inLineWrap ? displayOffset : 0));
1597 if (pos.ch == 0) x = 0;

Callers 2

getXFunction · 0.85
localCoordsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected