MCPcopy
hub / github.com/csev/py4e / coordsCharInner

Function coordsCharInner

tools/pythonauto/static/codemirrorepl/codemirror.js:1790–1828  ·  view source on GitHub ↗
(cm, lineObj, lineNo, x, y)

Source from the content-addressed store, hash-verified

1788 }
1789
1790 function coordsCharInner(cm, lineObj, lineNo, x, y) {
1791 var innerOff = y - heightAtLine(lineObj);
1792 var wrongLine = false, adjust = 2 * cm.display.wrapper.clientWidth;
1793 var preparedMeasure = prepareMeasureForLine(cm, lineObj);
1794
1795 function getX(ch) {
1796 var sp = cursorCoords(cm, Pos(lineNo, ch), "line", lineObj, preparedMeasure);
1797 wrongLine = true;
1798 if (innerOff > sp.bottom) return sp.left - adjust;
1799 else if (innerOff < sp.top) return sp.left + adjust;
1800 else wrongLine = false;
1801 return sp.left;
1802 }
1803
1804 var bidi = getOrder(lineObj), dist = lineObj.text.length;
1805 var from = lineLeft(lineObj), to = lineRight(lineObj);
1806 var fromX = getX(from), fromOutside = wrongLine, toX = getX(to), toOutside = wrongLine;
1807
1808 if (x > toX) return PosWithInfo(lineNo, to, toOutside, 1);
1809 // Do a binary search between these bounds.
1810 for (;;) {
1811 if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) {
1812 var ch = x < fromX || x - fromX <= toX - x ? from : to;
1813 var xDiff = x - (ch == from ? fromX : toX);
1814 while (isExtendingChar(lineObj.text.charAt(ch))) ++ch;
1815 var pos = PosWithInfo(lineNo, ch, ch == from ? fromOutside : toOutside,
1816 xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0);
1817 return pos;
1818 }
1819 var step = Math.ceil(dist / 2), middle = from + step;
1820 if (bidi) {
1821 middle = from;
1822 for (var i = 0; i < step; ++i) middle = moveVisually(lineObj, middle, 1);
1823 }
1824 var middleX = getX(middle);
1825 if (middleX > x) {to = middle; toX = middleX; if (toOutside = wrongLine) toX += 1000; dist = step;}
1826 else {from = middle; fromX = middleX; fromOutside = wrongLine; dist -= step;}
1827 }
1828 }
1829
1830 var measureText;
1831 // Compute the default text height.

Callers 1

coordsCharFunction · 0.70

Calls 9

prepareMeasureForLineFunction · 0.85
heightAtLineFunction · 0.70
getOrderFunction · 0.70
lineLeftFunction · 0.70
lineRightFunction · 0.70
getXFunction · 0.70
PosWithInfoFunction · 0.70
moveVisuallyFunction · 0.70
isExtendingCharFunction · 0.70

Tested by

no test coverage detected