MCPcopy
hub / github.com/jagenjo/webglstudio.js / patchDisplay

Function patchDisplay

editor/js/extra/codemirror/codemirror.js:850–890  ·  view source on GitHub ↗
(cm, updateNumbersFrom, dims)

Source from the content-addressed store, hash-verified

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

Callers 1

updateDisplayIfNeededFunction · 0.85

Calls 6

buildLineElementFunction · 0.85
rmFunction · 0.85
indexOfFunction · 0.85
updateLineForChangesFunction · 0.85
removeChildrenFunction · 0.85
lineNumberForFunction · 0.85

Tested by

no test coverage detected