MCPcopy
hub / github.com/DHTMLX/gantt / nodeAndOffsetInLineMap

Function nodeAndOffsetInLineMap

samples/common/codehighlight/codemirror.js:2431–2467  ·  view source on GitHub ↗
(map, ch, bias)

Source from the content-addressed store, hash-verified

2429 var nullRect = {left: 0, right: 0, top: 0, bottom: 0};
2430
2431 function nodeAndOffsetInLineMap(map, ch, bias) {
2432 var node, start, end, collapse, mStart, mEnd;
2433 // First, search the line map for the text node corresponding to,
2434 // or closest to, the target character.
2435 for (var i = 0; i < map.length; i += 3) {
2436 mStart = map[i];
2437 mEnd = map[i + 1];
2438 if (ch < mStart) {
2439 start = 0; end = 1;
2440 collapse = "left";
2441 } else if (ch < mEnd) {
2442 start = ch - mStart;
2443 end = start + 1;
2444 } else if (i == map.length - 3 || ch == mEnd && map[i + 3] > ch) {
2445 end = mEnd - mStart;
2446 start = end - 1;
2447 if (ch >= mEnd) { collapse = "right"; }
2448 }
2449 if (start != null) {
2450 node = map[i + 2];
2451 if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
2452 { collapse = bias; }
2453 if (bias == "left" && start == 0)
2454 { while (i && map[i - 2] == map[i - 3] && map[i - 1].insertLeft) {
2455 node = map[(i -= 3) + 2];
2456 collapse = "left";
2457 } }
2458 if (bias == "right" && start == mEnd - mStart)
2459 { while (i < map.length - 3 && map[i + 3] == map[i + 4] && !map[i + 5].insertLeft) {
2460 node = map[(i += 3) + 2];
2461 collapse = "right";
2462 } }
2463 break
2464 }
2465 }
2466 return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd}
2467 }
2468
2469 function getUsefulRect(rects, bias) {
2470 var rect = nullRect;

Callers 2

measureCharInnerFunction · 0.85
posToDOMFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected