MCPcopy Create free account
hub / github.com/TruthHun/BookStack / nodeAndOffsetInLineMap

Function nodeAndOffsetInLineMap

static/mergely/lib/codemirror.js:2646–2681  ·  view source on GitHub ↗
(map, ch, bias)

Source from the content-addressed store, hash-verified

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

Callers 2

posToDOMFunction · 0.70
measureCharInnerFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected