MCPcopy Index your code
hub / github.com/ronreiter/interactive-tutorials / cursorCoords

Function cursorCoords

static/js/codemirror/codemirror.js:1076–1110  ·  view source on GitHub ↗
(cm, pos, context, lineObj, measurement)

Source from the content-addressed store, hash-verified

1074 }
1075
1076 function cursorCoords(cm, pos, context, lineObj, measurement) {
1077 lineObj = lineObj || getLine(cm.doc, pos.line);
1078 if (!measurement) measurement = measureLine(cm, lineObj);
1079 function get(ch, right) {
1080 var m = measureChar(cm, lineObj, ch, measurement);
1081 if (right) m.left = m.right; else m.right = m.left;
1082 return intoCoordSystem(cm, lineObj, m, context);
1083 }
1084 var order = getOrder(lineObj), ch = pos.ch;
1085 if (!order) return get(ch);
1086 var main, other, linedir = order[0].level;
1087 for (var i = 0; i < order.length; ++i) {
1088 var part = order[i], rtl = part.level % 2, nb, here;
1089 if (part.from < ch && part.to > ch) return get(ch, rtl);
1090 var left = rtl ? part.to : part.from, right = rtl ? part.from : part.to;
1091 if (left == ch) {
1092 // IE returns bogus offsets and widths for edges where the
1093 // direction flips, but only for the side with the lower
1094 // level. So we try to use the side with the higher level.
1095 if (i && part.level < (nb = order[i-1]).level) here = get(nb.level % 2 ? nb.from : nb.to - 1, true);
1096 else here = get(rtl && part.from != part.to ? ch - 1 : ch);
1097 if (rtl == linedir) main = here; else other = here;
1098 } else if (right == ch) {
1099 var nb = i < order.length - 1 && order[i+1];
1100 if (!rtl && nb && nb.from == nb.to) continue;
1101 if (nb && part.level < nb.level) here = get(nb.level % 2 ? nb.to - 1 : nb.from);
1102 else here = get(rtl ? ch : ch - 1, true);
1103 if (rtl == linedir) main = here; else other = here;
1104 }
1105 }
1106 if (linedir && !ch) other = get(order[0].to - 1);
1107 if (!main) return other;
1108 if (other) main.other = other;
1109 return main;
1110 }
1111
1112 function PosMaybeOutside(line, ch, outside) {
1113 var pos = new Pos(line, ch);

Callers 6

updateSelectionFunction · 0.85
updateSelectionCursorFunction · 0.85
getXFunction · 0.85
endOperationFunction · 0.85
scrollPosIntoViewFunction · 0.85
codemirror.jsFile · 0.85

Calls 4

getLineFunction · 0.85
measureLineFunction · 0.85
getOrderFunction · 0.85
getFunction · 0.70

Tested by

no test coverage detected