MCPcopy
hub / github.com/witheve/Eve / updateDisplayIfNeeded

Function updateDisplayIfNeeded

src/codemirror.js:677–747  ·  view source on GitHub ↗
(cm, update)

Source from the content-addressed store, hash-verified

675 // (returning false) when there is nothing to be done and forced is
676 // false.
677 function updateDisplayIfNeeded(cm, update) {
678 var display = cm.display, doc = cm.doc;
679
680 if (update.editorIsHidden) {
681 resetView(cm);
682 return false;
683 }
684
685 // Bail out if the visible area is already rendered and nothing changed.
686 if (!update.force &&
687 update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
688 (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
689 display.renderedView == display.view && countDirtyView(cm) == 0)
690 return false;
691
692 if (maybeUpdateLineNumberWidth(cm)) {
693 resetView(cm);
694 update.dims = getDimensions(cm);
695 }
696
697 // Compute a suitable new viewport (from & to)
698 var end = doc.first + doc.size;
699 var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first);
700 var to = Math.min(end, update.visible.to + cm.options.viewportMargin);
701 if (display.viewFrom < from && from - display.viewFrom < 20) from = Math.max(doc.first, display.viewFrom);
702 if (display.viewTo > to && display.viewTo - to < 20) to = Math.min(end, display.viewTo);
703 if (sawCollapsedSpans) {
704 from = visualLineNo(cm.doc, from);
705 to = visualLineEndNo(cm.doc, to);
706 }
707
708 var different = from != display.viewFrom || to != display.viewTo ||
709 display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth;
710 adjustView(cm, from, to);
711
712 display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom));
713 // Position the mover div to align with the current scroll position
714 cm.display.mover.style.top = display.viewOffset + "px";
715
716 var toUpdate = countDirtyView(cm);
717 if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
718 (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
719 return false;
720
721 // For big changes, we hide the enclosing element during the
722 // update, since that speeds up the operations on most browsers.
723 var focused = activeElt();
724 if (toUpdate > 4) display.lineDiv.style.display = "none";
725 patchDisplay(cm, display.updateLineNumbers, update.dims);
726 if (toUpdate > 4) display.lineDiv.style.display = "";
727 display.renderedView = display.view;
728 // There might have been a widget with a focused element that got
729 // hidden or updated, if so re-focus it.
730 if (focused && activeElt() != focused && focused.offsetHeight) focused.focus();
731
732 // Prevent selection and cursors from interfering with the scroll
733 // width and height.
734 removeChildren(display.cursorDiv);

Callers 3

postUpdateDisplayFunction · 0.85
updateDisplaySimpleFunction · 0.85
endOperation_W1Function · 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
activeEltFunction · 0.85
patchDisplayFunction · 0.85
removeChildrenFunction · 0.85

Tested by

no test coverage detected