MCPcopy
hub / github.com/csev/py4e / patchDisplay

Function patchDisplay

tools/pythonauto/static/codemirror/codemirror.js:617–682  ·  view source on GitHub ↗
(cm, from, to, intact, updateNumbersFrom)

Source from the content-addressed store, hash-verified

615 }
616
617 function patchDisplay(cm, from, to, intact, updateNumbersFrom) {
618 var dims = getDimensions(cm);
619 var display = cm.display, lineNumbers = cm.options.lineNumbers;
620 if (!intact.length && (!webkit || !cm.display.currentWheelTarget))
621 removeChildren(display.lineDiv);
622 var container = display.lineDiv, cur = container.firstChild;
623
624 function rm(node) {
625 var next = node.nextSibling;
626 if (webkit && mac && cm.display.currentWheelTarget == node) {
627 node.style.display = "none";
628 node.lineObj = null;
629 } else {
630 node.parentNode.removeChild(node);
631 }
632 return next;
633 }
634
635 var nextIntact = intact.shift(), lineN = from;
636 cm.doc.iter(from, to, function(line) {
637 if (nextIntact && nextIntact.to == lineN) nextIntact = intact.shift();
638 if (lineIsHidden(cm.doc, line)) {
639 if (line.height != 0) updateLineHeight(line, 0);
640 if (line.widgets && cur && cur.previousSibling) for (var i = 0; i < line.widgets.length; ++i) {
641 var w = line.widgets[i];
642 if (w.showIfHidden) {
643 var prev = cur.previousSibling;
644 if (/pre/i.test(prev.nodeName)) {
645 var wrap = elt("div", null, null, "position: relative");
646 prev.parentNode.replaceChild(wrap, prev);
647 wrap.appendChild(prev);
648 prev = wrap;
649 }
650 var wnode = prev.appendChild(elt("div", [w.node], "CodeMirror-linewidget"));
651 if (!w.handleMouseEvents) wnode.ignoreEvents = true;
652 positionLineWidget(w, wnode, prev, dims);
653 }
654 }
655 } else if (nextIntact && nextIntact.from <= lineN && nextIntact.to > lineN) {
656 // This line is intact. Skip to the actual node. Update its
657 // line number if needed.
658 while (cur.lineObj != line) cur = rm(cur);
659 if (lineNumbers && updateNumbersFrom <= lineN && cur.lineNumber)
660 setTextContent(cur.lineNumber, lineNumberFor(cm.options, lineN));
661 cur = cur.nextSibling;
662 } else {
663 // For lines with widgets, make an attempt to find and reuse
664 // the existing element, so that widgets aren't needlessly
665 // removed and re-inserted into the dom
666 if (line.widgets) for (var j = 0, search = cur, reuse; search && j < 20; ++j, search = search.nextSibling)
667 if (search.lineObj == line && /div/i.test(search.nodeName)) { reuse = search; break; }
668 // This line needs to be generated.
669 var lineNode = buildLineElement(cm, line, lineN, dims, reuse);
670 if (lineNode != reuse) {
671 container.insertBefore(lineNode, cur);
672 } else {
673 while (cur != reuse) cur = rm(cur);
674 cur = cur.nextSibling;

Callers 1

updateDisplayInnerFunction · 0.70

Calls 13

setTextContentFunction · 0.85
getDimensionsFunction · 0.70
removeChildrenFunction · 0.70
lineIsHiddenFunction · 0.70
updateLineHeightFunction · 0.70
eltFunction · 0.70
positionLineWidgetFunction · 0.70
rmFunction · 0.70
lineNumberForFunction · 0.70
buildLineElementFunction · 0.70
shiftMethod · 0.45
appendChildMethod · 0.45

Tested by

no test coverage detected