MCPcopy Index your code
hub / github.com/csev/py4e / patchDisplay

Function patchDisplay

tools/pythonauto/static/codemirrorepl/codemirrorepl.js:1246–1285  ·  view source on GitHub ↗
(from, to, intact)

Source from the content-addressed store, hash-verified

1244 }
1245
1246 function patchDisplay(from, to, intact) {
1247 // The first pass removes the DOM nodes that aren't intact.
1248 if (!intact.length) lineDiv.innerHTML = "";
1249 else {
1250 function killNode(node) {
1251 var tmp = node.nextSibling;
1252 node.parentNode.removeChild(node);
1253 return tmp;
1254 }
1255 var domPos = 0, curNode = lineDiv.firstChild, n;
1256 for (var i = 0; i < intact.length; ++i) {
1257 var cur = intact[i];
1258 while (cur.domStart > domPos) {curNode = killNode(curNode); domPos++;}
1259 for (var j = 0, e = cur.to - cur.from; j < e; ++j) {curNode = curNode.nextSibling; domPos++;}
1260 }
1261 while (curNode) curNode = killNode(curNode);
1262 }
1263 // This pass fills in the lines that actually changed.
1264 var nextIntact = intact.shift(), curNode = lineDiv.firstChild, j = from;
1265 var scratch = document.createElement("div");
1266 doc.iter(from, to, function(line) {
1267 if (nextIntact && nextIntact.to == j) nextIntact = intact.shift();
1268 if (!nextIntact || nextIntact.from > j) {
1269 if (line.hidden) var html = scratch.innerHTML = "<pre></pre>";
1270 else {
1271 var html = '<pre' + (line.className ? ' class="' + line.className + '"' : '') + '>'
1272 + line.getHTML(makeTab) + '</pre>';
1273 // Kludge to make sure the styled element lies behind the selection (by z-index)
1274 if (line.bgClassName)
1275 html = '<div style="position: relative"><pre class="' + line.bgClassName +
1276 '" style="position: absolute; left: 0; right: 0; top: 0; bottom: 0; z-index: -2">&#160;</pre>' + html + "</div>";
1277 }
1278 scratch.innerHTML = html;
1279 lineDiv.insertBefore(scratch.firstChild, curNode);
1280 } else {
1281 curNode = curNode.nextSibling;
1282 }
1283 ++j;
1284 });
1285 }
1286
1287 function updateGutter() {
1288 if (!options.gutter && !options.lineNumbers) return;

Callers 1

updateDisplayFunction · 0.70

Calls 3

killNodeFunction · 0.85
shiftMethod · 0.45
insertBeforeMethod · 0.45

Tested by

no test coverage detected