MCPcopy Create free account
hub / github.com/TruthHun/BookStack / updateDisplayIfNeeded

Function updateDisplayIfNeeded

static/mergely/lib/codemirror.js:675–745  ·  view source on GitHub ↗
(cm, update)

Source from the content-addressed store, hash-verified

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

Callers 3

postUpdateDisplayFunction · 0.70
updateDisplaySimpleFunction · 0.70
endOperation_W1Function · 0.70

Calls 13

resetViewFunction · 0.70
countDirtyViewFunction · 0.70
getDimensionsFunction · 0.70
visualLineNoFunction · 0.70
visualLineEndNoFunction · 0.70
adjustViewFunction · 0.70
heightAtLineFunction · 0.70
getLineFunction · 0.70
activeEltFunction · 0.70
patchDisplayFunction · 0.70
removeChildrenFunction · 0.70

Tested by

no test coverage detected