MCPcopy Index your code
hub / github.com/csev/py4e / calculateScrollPos

Function calculateScrollPos

tools/pythonauto/static/codemirrorepl/codemirror.js:3524–3550  ·  view source on GitHub ↗
(cm, x1, y1, x2, y2)

Source from the content-addressed store, hash-verified

3522 // scrollLeft properties. When these are undefined, the
3523 // vertical/horizontal position does not need to be adjusted.
3524 function calculateScrollPos(cm, x1, y1, x2, y2) {
3525 var display = cm.display, snapMargin = textHeight(cm.display);
3526 if (y1 < 0) y1 = 0;
3527 var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;
3528 var screen = display.scroller.clientHeight - scrollerCutOff, result = {};
3529 var docBottom = cm.doc.height + paddingVert(display);
3530 var atTop = y1 < snapMargin, atBottom = y2 > docBottom - snapMargin;
3531 if (y1 < screentop) {
3532 result.scrollTop = atTop ? 0 : y1;
3533 } else if (y2 > screentop + screen) {
3534 var newTop = Math.min(y1, (atBottom ? docBottom : y2) - screen);
3535 if (newTop != screentop) result.scrollTop = newTop;
3536 }
3537
3538 var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;
3539 var screenw = display.scroller.clientWidth - scrollerCutOff;
3540 x1 += display.gutters.offsetWidth; x2 += display.gutters.offsetWidth;
3541 var gutterw = display.gutters.offsetWidth;
3542 var atLeft = x1 < gutterw + 10;
3543 if (x1 < screenleft + gutterw || atLeft) {
3544 if (atLeft) x1 = 0;
3545 result.scrollLeft = Math.max(0, x1 - 10 - gutterw);
3546 } else if (x2 > screenw + screenleft - 3) {
3547 result.scrollLeft = x2 + 10 - screenw;
3548 }
3549 return result;
3550 }
3551
3552 // Store a relative adjustment to the scroll position in the current
3553 // operation (to be applied when the operation finishes).

Callers 4

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

Calls 2

textHeightFunction · 0.70
paddingVertFunction · 0.70

Tested by

no test coverage detected