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

Function scrollPosIntoView

static/mergely/lib/codemirror.js:4603–4624  ·  view source on GitHub ↗
(cm, pos, end, margin)

Source from the content-addressed store, hash-verified

4601 // it actually became visible (as line heights are accurately
4602 // measured, the position of something may 'drift' during drawing).
4603 function scrollPosIntoView(cm, pos, end, margin) {
4604 if (margin == null) margin = 0;
4605 for (var limit = 0; limit < 5; limit++) {
4606 var changed = false, coords = cursorCoords(cm, pos);
4607 var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
4608 var scrollPos = calculateScrollPos(cm, Math.min(coords.left, endCoords.left),
4609 Math.min(coords.top, endCoords.top) - margin,
4610 Math.max(coords.left, endCoords.left),
4611 Math.max(coords.bottom, endCoords.bottom) + margin);
4612 var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
4613 if (scrollPos.scrollTop != null) {
4614 setScrollTop(cm, scrollPos.scrollTop);
4615 if (Math.abs(cm.doc.scrollTop - startTop) > 1) changed = true;
4616 }
4617 if (scrollPos.scrollLeft != null) {
4618 setScrollLeft(cm, scrollPos.scrollLeft);
4619 if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) changed = true;
4620 }
4621 if (!changed) break;
4622 }
4623 return coords;
4624 }
4625
4626 // Scroll a given set of coordinates into view (immediately).
4627 function scrollIntoView(cm, x1, y1, x2, y2) {

Callers 1

endOperation_finishFunction · 0.70

Calls 4

cursorCoordsFunction · 0.70
calculateScrollPosFunction · 0.70
setScrollTopFunction · 0.70
setScrollLeftFunction · 0.70

Tested by

no test coverage detected