MCPcopy Index your code
hub / github.com/csev/py4e / coordsCharInner

Function coordsCharInner

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

Source from the content-addressed store, hash-verified

1278 }
1279
1280 function coordsCharInner(cm, lineObj, lineNo, x, y) {
1281 var innerOff = y - heightAtLine(cm, lineObj);
1282 var wrongLine = false, adjust = 2 * cm.display.wrapper.clientWidth;
1283 var measurement = measureLine(cm, lineObj);
1284
1285 function getX(ch) {
1286 var sp = cursorCoords(cm, Pos(lineNo, ch), "line",
1287 lineObj, measurement);
1288 wrongLine = true;
1289 if (innerOff > sp.bottom) return sp.left - adjust;
1290 else if (innerOff < sp.top) return sp.left + adjust;
1291 else wrongLine = false;
1292 return sp.left;
1293 }
1294
1295 var bidi = getOrder(lineObj), dist = lineObj.text.length;
1296 var from = lineLeft(lineObj), to = lineRight(lineObj);
1297 var fromX = getX(from), fromOutside = wrongLine, toX = getX(to), toOutside = wrongLine;
1298
1299 if (x > toX) return PosWithInfo(lineNo, to, toOutside, 1);
1300 // Do a binary search between these bounds.
1301 for (;;) {
1302 if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) {
1303 var ch = x < fromX || x - fromX <= toX - x ? from : to;
1304 var xDiff = x - (ch == from ? fromX : toX);
1305 while (isExtendingChar(lineObj.text.charAt(ch))) ++ch;
1306 var pos = PosWithInfo(lineNo, ch, ch == from ? fromOutside : toOutside,
1307 xDiff < 0 ? -1 : xDiff ? 1 : 0);
1308 return pos;
1309 }
1310 var step = Math.ceil(dist / 2), middle = from + step;
1311 if (bidi) {
1312 middle = from;
1313 for (var i = 0; i < step; ++i) middle = moveVisually(lineObj, middle, 1);
1314 }
1315 var middleX = getX(middle);
1316 if (middleX > x) {to = middle; toX = middleX; if (toOutside = wrongLine) toX += 1000; dist = step;}
1317 else {from = middle; fromX = middleX; fromOutside = wrongLine; dist -= step;}
1318 }
1319 }
1320
1321 var measureText;
1322 function textHeight(display) {

Callers 1

coordsCharFunction · 0.70

Calls 9

heightAtLineFunction · 0.70
measureLineFunction · 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