MCPcopy Create free account
hub / github.com/TextGeneratorio/text-generator.io / updateDisplayIfNeeded

Function updateDisplayIfNeeded

static/libs/codemirror.js:4167–4237  ·  view source on GitHub ↗
(cm, update)

Source from the content-addressed store, hash-verified

4165// (returning false) when there is nothing to be done and forced is
4166// false.
4167function updateDisplayIfNeeded(cm, update) {
4168 var display = cm.display, doc = cm.doc;
4169
4170 if (update.editorIsHidden) {
4171 resetView(cm);
4172 return false
4173 }
4174
4175 // Bail out if the visible area is already rendered and nothing changed.
4176 if (!update.force &&
4177 update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
4178 (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
4179 display.renderedView == display.view && countDirtyView(cm) == 0)
4180 { return false }
4181
4182 if (maybeUpdateLineNumberWidth(cm)) {
4183 resetView(cm);
4184 update.dims = getDimensions(cm);
4185 }
4186
4187 // Compute a suitable new viewport (from & to)
4188 var end = doc.first + doc.size;
4189 var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first);
4190 var to = Math.min(end, update.visible.to + cm.options.viewportMargin);
4191 if (display.viewFrom < from && from - display.viewFrom < 20) { from = Math.max(doc.first, display.viewFrom); }
4192 if (display.viewTo > to && display.viewTo - to < 20) { to = Math.min(end, display.viewTo); }
4193 if (sawCollapsedSpans) {
4194 from = visualLineNo(cm.doc, from);
4195 to = visualLineEndNo(cm.doc, to);
4196 }
4197
4198 var different = from != display.viewFrom || to != display.viewTo ||
4199 display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth;
4200 adjustView(cm, from, to);
4201
4202 display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom));
4203 // Position the mover div to align with the current scroll position
4204 cm.display.mover.style.top = display.viewOffset + "px";
4205
4206 var toUpdate = countDirtyView(cm);
4207 if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
4208 (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
4209 { return false }
4210
4211 // For big changes, we hide the enclosing element during the
4212 // update, since that speeds up the operations on most browsers.
4213 var selSnapshot = selectionSnapshot(cm);
4214 if (toUpdate > 4) { display.lineDiv.style.display = "none"; }
4215 patchDisplay(cm, display.updateLineNumbers, update.dims);
4216 if (toUpdate > 4) { display.lineDiv.style.display = ""; }
4217 display.renderedView = display.view;
4218 // There might have been a widget with a focused element that got
4219 // hidden or updated, if so re-focus it.
4220 restoreSelection(selSnapshot);
4221
4222 // Prevent selection and cursors from interfering with the scroll
4223 // width and height.
4224 removeChildren(display.cursorDiv);

Callers 3

endOperation_W1Function · 0.85
postUpdateDisplayFunction · 0.85
updateDisplaySimpleFunction · 0.85

Calls 14

resetViewFunction · 0.85
countDirtyViewFunction · 0.85
getDimensionsFunction · 0.85
visualLineNoFunction · 0.85
visualLineEndNoFunction · 0.85
adjustViewFunction · 0.85
heightAtLineFunction · 0.85
getLineFunction · 0.85
selectionSnapshotFunction · 0.85
patchDisplayFunction · 0.85
restoreSelectionFunction · 0.85

Tested by

no test coverage detected