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

Function calculateScrollPos

static/mergely/lib/codemirror.js:4637–4663  ·  view source on GitHub ↗
(cm, x1, y1, x2, y2)

Source from the content-addressed store, hash-verified

4635 // scrollLeft properties. When these are undefined, the
4636 // vertical/horizontal position does not need to be adjusted.
4637 function calculateScrollPos(cm, x1, y1, x2, y2) {
4638 var display = cm.display, snapMargin = textHeight(cm.display);
4639 if (y1 < 0) y1 = 0;
4640 var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;
4641 var screen = displayHeight(cm), result = {};
4642 if (y2 - y1 > screen) y2 = y1 + screen;
4643 var docBottom = cm.doc.height + paddingVert(display);
4644 var atTop = y1 < snapMargin, atBottom = y2 > docBottom - snapMargin;
4645 if (y1 < screentop) {
4646 result.scrollTop = atTop ? 0 : y1;
4647 } else if (y2 > screentop + screen) {
4648 var newTop = Math.min(y1, (atBottom ? docBottom : y2) - screen);
4649 if (newTop != screentop) result.scrollTop = newTop;
4650 }
4651
4652 var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;
4653 var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0);
4654 var tooWide = x2 - x1 > screenw;
4655 if (tooWide) x2 = x1 + screenw;
4656 if (x1 < 10)
4657 result.scrollLeft = 0;
4658 else if (x1 < screenleft)
4659 result.scrollLeft = Math.max(0, x1 - (tooWide ? 0 : 10));
4660 else if (x2 > screenw + screenleft - 3)
4661 result.scrollLeft = x2 + (tooWide ? 0 : 10) - screenw;
4662 return result;
4663 }
4664
4665 // Store a relative adjustment to the scroll position in the current
4666 // operation (to be applied when the operation finishes).

Callers 4

scrollPosIntoViewFunction · 0.70
scrollIntoViewFunction · 0.70
resolveScrollToPosFunction · 0.70
codemirror.jsFile · 0.70

Calls 4

textHeightFunction · 0.70
displayHeightFunction · 0.70
paddingVertFunction · 0.70
displayWidthFunction · 0.70

Tested by

no test coverage detected