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

Function patchDisplay

static/editor.md/lib/codemirror/lib/codemirror.js:832–872  ·  view source on GitHub ↗
(cm, updateNumbersFrom, dims)

Source from the content-addressed store, hash-verified

830 // that are not there yet, and updating the ones that are out of
831 // date.
832 function patchDisplay(cm, updateNumbersFrom, dims) {
833 var display = cm.display, lineNumbers = cm.options.lineNumbers;
834 var container = display.lineDiv, cur = container.firstChild;
835
836 function rm(node) {
837 var next = node.nextSibling;
838 // Works around a throw-scroll bug in OS X Webkit
839 if (webkit && mac && cm.display.currentWheelTarget == node)
840 node.style.display = "none";
841 else
842 node.parentNode.removeChild(node);
843 return next;
844 }
845
846 var view = display.view, lineN = display.viewFrom;
847 // Loop over the elements in the view, syncing cur (the DOM nodes
848 // in display.lineDiv) with the view as we go.
849 for (var i = 0; i < view.length; i++) {
850 var lineView = view[i];
851 if (lineView.hidden) {
852 } else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
853 var node = buildLineElement(cm, lineView, lineN, dims);
854 container.insertBefore(node, cur);
855 } else { // Already drawn
856 while (cur != lineView.node) cur = rm(cur);
857 var updateNumber = lineNumbers && updateNumbersFrom != null &&
858 updateNumbersFrom <= lineN && lineView.lineNumber;
859 if (lineView.changes) {
860 if (indexOf(lineView.changes, "gutter") > -1) updateNumber = false;
861 updateLineForChanges(cm, lineView, lineN, dims);
862 }
863 if (updateNumber) {
864 removeChildren(lineView.lineNumber);
865 lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)));
866 }
867 cur = lineView.node.nextSibling;
868 }
869 lineN += lineView.size;
870 }
871 while (cur) cur = rm(cur);
872 }
873
874 // When an aspect of a line changes, a string is added to
875 // lineView.changes. This updates the relevant part of the line's

Callers 1

updateDisplayIfNeededFunction · 0.70

Calls 6

buildLineElementFunction · 0.70
rmFunction · 0.70
indexOfFunction · 0.70
updateLineForChangesFunction · 0.70
removeChildrenFunction · 0.70
lineNumberForFunction · 0.70

Tested by

no test coverage detected