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

Function patchDisplay

static/js/codemirror/codemirror.js:565–627  ·  view source on GitHub ↗
(cm, from, to, intact, updateNumbersFrom)

Source from the content-addressed store, hash-verified

563 }
564
565 function patchDisplay(cm, from, to, intact, updateNumbersFrom) {
566 var dims = getDimensions(cm);
567 var display = cm.display, lineNumbers = cm.options.lineNumbers;
568 if (!intact.length && (!webkit || !cm.display.currentWheelTarget))
569 removeChildren(display.lineDiv);
570 var container = display.lineDiv, cur = container.firstChild;
571
572 function rm(node) {
573 var next = node.nextSibling;
574 if (webkit && mac && cm.display.currentWheelTarget == node) {
575 node.style.display = "none";
576 node.lineObj = null;
577 } else {
578 node.parentNode.removeChild(node);
579 }
580 return next;
581 }
582
583 var nextIntact = intact.shift(), lineN = from;
584 cm.doc.iter(from, to, function(line) {
585 if (nextIntact && nextIntact.to == lineN) nextIntact = intact.shift();
586 if (lineIsHidden(cm.doc, line)) {
587 if (line.height != 0) updateLineHeight(line, 0);
588 if (line.widgets && cur.previousSibling) for (var i = 0; i < line.widgets.length; ++i)
589 if (line.widgets[i].showIfHidden) {
590 var prev = cur.previousSibling;
591 if (/pre/i.test(prev.nodeName)) {
592 var wrap = elt("div", null, null, "position: relative");
593 prev.parentNode.replaceChild(wrap, prev);
594 wrap.appendChild(prev);
595 prev = wrap;
596 }
597 var wnode = prev.appendChild(elt("div", [line.widgets[i].node], "CodeMirror-linewidget"));
598 positionLineWidget(line.widgets[i], wnode, prev, dims);
599 }
600 } else if (nextIntact && nextIntact.from <= lineN && nextIntact.to > lineN) {
601 // This line is intact. Skip to the actual node. Update its
602 // line number if needed.
603 while (cur.lineObj != line) cur = rm(cur);
604 if (lineNumbers && updateNumbersFrom <= lineN && cur.lineNumber)
605 setTextContent(cur.lineNumber, lineNumberFor(cm.options, lineN));
606 cur = cur.nextSibling;
607 } else {
608 // For lines with widgets, make an attempt to find and reuse
609 // the existing element, so that widgets aren't needlessly
610 // removed and re-inserted into the dom
611 if (line.widgets) for (var j = 0, search = cur, reuse; search && j < 20; ++j, search = search.nextSibling)
612 if (search.lineObj == line && /div/i.test(search.nodeName)) { reuse = search; break; }
613 // This line needs to be generated.
614 var lineNode = buildLineElement(cm, line, lineN, dims, reuse);
615 if (lineNode != reuse) {
616 container.insertBefore(lineNode, cur);
617 } else {
618 while (cur != reuse) cur = rm(cur);
619 cur = cur.nextSibling;
620 }
621
622 lineNode.lineObj = line;

Callers 1

updateDisplayInnerFunction · 0.85

Calls 12

getDimensionsFunction · 0.85
removeChildrenFunction · 0.85
lineIsHiddenFunction · 0.85
updateLineHeightFunction · 0.85
eltFunction · 0.85
positionLineWidgetFunction · 0.85
setTextContentFunction · 0.85
lineNumberForFunction · 0.85
buildLineElementFunction · 0.85
replaceChildMethod · 0.80
rmFunction · 0.70
testMethod · 0.45

Tested by

no test coverage detected