MCPcopy Create free account
hub / github.com/TextGeneratorio/text-generator.io / nodeAndOffsetInLineMap

Function nodeAndOffsetInLineMap

static/libs/codemirror.js:2499–2535  ·  view source on GitHub ↗
(map$$1, ch, bias)

Source from the content-addressed store, hash-verified

2497var nullRect = {left: 0, right: 0, top: 0, bottom: 0};
2498
2499function nodeAndOffsetInLineMap(map$$1, ch, bias) {
2500 var node, start, end, collapse, mStart, mEnd;
2501 // First, search the line map for the text node corresponding to,
2502 // or closest to, the target character.
2503 for (var i = 0; i < map$$1.length; i += 3) {
2504 mStart = map$$1[i];
2505 mEnd = map$$1[i + 1];
2506 if (ch < mStart) {
2507 start = 0; end = 1;
2508 collapse = "left";
2509 } else if (ch < mEnd) {
2510 start = ch - mStart;
2511 end = start + 1;
2512 } else if (i == map$$1.length - 3 || ch == mEnd && map$$1[i + 3] > ch) {
2513 end = mEnd - mStart;
2514 start = end - 1;
2515 if (ch >= mEnd) { collapse = "right"; }
2516 }
2517 if (start != null) {
2518 node = map$$1[i + 2];
2519 if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
2520 { collapse = bias; }
2521 if (bias == "left" && start == 0)
2522 { while (i && map$$1[i - 2] == map$$1[i - 3] && map$$1[i - 1].insertLeft) {
2523 node = map$$1[(i -= 3) + 2];
2524 collapse = "left";
2525 } }
2526 if (bias == "right" && start == mEnd - mStart)
2527 { while (i < map$$1.length - 3 && map$$1[i + 3] == map$$1[i + 4] && !map$$1[i + 5].insertLeft) {
2528 node = map$$1[(i += 3) + 2];
2529 collapse = "right";
2530 } }
2531 break
2532 }
2533 }
2534 return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd}
2535}
2536
2537function getUsefulRect(rects, bias) {
2538 var rect = nullRect;

Callers 2

measureCharInnerFunction · 0.85
posToDOMFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected