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

Function updateDisplay

tools/pythonauto/static/codemirrorepl/codemirrorepl.js:1129–1221  ·  view source on GitHub ↗
(changes, suppressCallback)

Source from the content-addressed store, hash-verified

1127 // determine which DOM updates have to be made, and makes the
1128 // updates.
1129 function updateDisplay(changes, suppressCallback) {
1130 if (!scroller.clientWidth) {
1131 showingFrom = showingTo = displayOffset = 0;
1132 return;
1133 }
1134 // Compute the new visible window
1135 var visible = visibleLines();
1136 // Bail out if the visible area is already rendered and nothing changed.
1137 if (changes !== true && changes.length == 0 && visible.from > showingFrom && visible.to < showingTo) return;
1138 var from = Math.max(visible.from - 100, 0), to = Math.min(doc.size, visible.to + 100);
1139 if (showingFrom < from && from - showingFrom < 20) from = showingFrom;
1140 if (showingTo > to && showingTo - to < 20) to = Math.min(doc.size, showingTo);
1141
1142 // Create a range of theoretically intact lines, and punch holes
1143 // in that using the change info.
1144 var intact = changes === true ? [] :
1145 computeIntact([{from: showingFrom, to: showingTo, domStart: 0}], changes);
1146 // Clip off the parts that won't be visible
1147 var intactLines = 0;
1148 for (var i = 0; i < intact.length; ++i) {
1149 var range = intact[i];
1150 if (range.from < from) {range.domStart += (from - range.from); range.from = from;}
1151 if (range.to > to) range.to = to;
1152 if (range.from >= range.to) intact.splice(i--, 1);
1153 else intactLines += range.to - range.from;
1154 }
1155 if (intactLines == to - from && from == showingFrom && to == showingTo) return;
1156 intact.sort(function(a, b) {return a.domStart - b.domStart;});
1157
1158 var th = textHeight(), gutterDisplay = gutter.style.display;
1159 lineDiv.style.display = "none";
1160 patchDisplay(from, to, intact);
1161 lineDiv.style.display = gutter.style.display = "";
1162
1163 // Position the mover div to align with the lines it's supposed
1164 // to be showing (which will cover the visible display)
1165 var different = from != showingFrom || to != showingTo || lastSizeC != scroller.clientHeight + th;
1166 // This is just a bogus formula that detects when the editor is
1167 // resized or the font size changes.
1168 if (different) lastSizeC = scroller.clientHeight + th;
1169 showingFrom = from; showingTo = to;
1170 displayOffset = heightAtLine(doc, from);
1171 mover.style.top = (displayOffset * th) + "px";
1172 if (scroller.clientHeight)
1173 code.style.height = (doc.height * th + 2 * paddingTop()) + "px";
1174
1175 // Since this is all rather error prone, it is honoured with the
1176 // only assertion in the whole file.
1177 if (lineDiv.childNodes.length != showingTo - showingFrom)
1178 throw new Error("BAD PATCH! " + JSON.stringify(intact) + " size=" + (showingTo - showingFrom) +
1179 " nodes=" + lineDiv.childNodes.length);
1180
1181 function checkHeights() {
1182 maxWidth = scroller.clientWidth;
1183 var curNode = lineDiv.firstChild, heightChanged = false;
1184 doc.iter(showingFrom, showingTo, function(line) {
1185 if (!line.hidden) {
1186 var height = Math.round(curNode.offsetHeight / th) || 1;

Callers 2

CodeMirrorFunction · 0.70
endOperationFunction · 0.70

Calls 10

checkHeightsFunction · 0.85
stringWidthFunction · 0.85
updateGutterFunction · 0.85
visibleLinesFunction · 0.70
computeIntactFunction · 0.70
textHeightFunction · 0.70
patchDisplayFunction · 0.70
heightAtLineFunction · 0.70
paddingTopFunction · 0.70
updateSelectionFunction · 0.70

Tested by

no test coverage detected