MCPcopy
hub / github.com/hokein/electron-sample-apps / patchDisplay

Function patchDisplay

mini-code-editor/cm/lib/codemirror.js:1046–1085  ·  view source on GitHub ↗
(from, to, intact)

Source from the content-addressed store, hash-verified

1044 }
1045
1046 function patchDisplay(from, to, intact) {
1047 // The first pass removes the DOM nodes that aren't intact.
1048 if (!intact.length) lineDiv.innerHTML = "";
1049 else {
1050 function killNode(node) {
1051 var tmp = node.nextSibling;
1052 node.parentNode.removeChild(node);
1053 return tmp;
1054 }
1055 var domPos = 0, curNode = lineDiv.firstChild, n;
1056 for (var i = 0; i < intact.length; ++i) {
1057 var cur = intact[i];
1058 while (cur.domStart > domPos) {curNode = killNode(curNode); domPos++;}
1059 for (var j = 0, e = cur.to - cur.from; j < e; ++j) {curNode = curNode.nextSibling; domPos++;}
1060 }
1061 while (curNode) curNode = killNode(curNode);
1062 }
1063 // This pass fills in the lines that actually changed.
1064 var nextIntact = intact.shift(), curNode = lineDiv.firstChild, j = from;
1065 var scratch = document.createElement("div");
1066 doc.iter(from, to, function(line) {
1067 if (nextIntact && nextIntact.to == j) nextIntact = intact.shift();
1068 if (!nextIntact || nextIntact.from > j) {
1069 if (line.hidden) var html = scratch.innerHTML = "<pre></pre>";
1070 else {
1071 var html = '<pre' + (line.className ? ' class="' + line.className + '"' : '') + '>'
1072 + line.getHTML(makeTab) + '</pre>';
1073 // Kludge to make sure the styled element lies behind the selection (by z-index)
1074 if (line.bgClassName)
1075 html = '<div style="position: relative"><pre class="' + line.bgClassName +
1076 '" style="position: absolute; left: 0; right: 0; top: 0; bottom: 0; z-index: -2">&#160;</pre>' + html + "</div>";
1077 }
1078 scratch.innerHTML = html;
1079 lineDiv.insertBefore(scratch.firstChild, curNode);
1080 } else {
1081 curNode = curNode.nextSibling;
1082 }
1083 ++j;
1084 });
1085 }
1086
1087 function updateGutter() {
1088 if (!options.gutter && !options.lineNumbers) return;

Callers 1

updateDisplayFunction · 0.85

Calls 1

killNodeFunction · 0.85

Tested by

no test coverage detected