MCPcopy Index your code
hub / github.com/witheve/Eve / nodeAndOffsetInLineMap

Function nodeAndOffsetInLineMap

src/codemirror.js:2654–2689  ·  view source on GitHub ↗
(map, ch, bias)

Source from the content-addressed store, hash-verified

2652 var nullRect = {left: 0, right: 0, top: 0, bottom: 0};
2653
2654 function nodeAndOffsetInLineMap(map, ch, bias) {
2655 var node, start, end, collapse;
2656 // First, search the line map for the text node corresponding to,
2657 // or closest to, the target character.
2658 for (var i = 0; i < map.length; i += 3) {
2659 var mStart = map[i], mEnd = map[i + 1];
2660 if (ch < mStart) {
2661 start = 0; end = 1;
2662 collapse = "left";
2663 } else if (ch < mEnd) {
2664 start = ch - mStart;
2665 end = start + 1;
2666 } else if (i == map.length - 3 || ch == mEnd && map[i + 3] > ch) {
2667 end = mEnd - mStart;
2668 start = end - 1;
2669 if (ch >= mEnd) collapse = "right";
2670 }
2671 if (start != null) {
2672 node = map[i + 2];
2673 if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
2674 collapse = bias;
2675 if (bias == "left" && start == 0)
2676 while (i && map[i - 2] == map[i - 3] && map[i - 1].insertLeft) {
2677 node = map[(i -= 3) + 2];
2678 collapse = "left";
2679 }
2680 if (bias == "right" && start == mEnd - mStart)
2681 while (i < map.length - 3 && map[i + 3] == map[i + 4] && !map[i + 5].insertLeft) {
2682 node = map[(i += 3) + 2];
2683 collapse = "right";
2684 }
2685 break;
2686 }
2687 }
2688 return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd};
2689 }
2690
2691 function measureCharInner(cm, prepared, ch, bias) {
2692 var place = nodeAndOffsetInLineMap(prepared.map, ch, bias);

Callers 2

posToDOMFunction · 0.85
measureCharInnerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected