MCPcopy Create free account
hub / github.com/csev/py4e / calculateScrollPos

Function calculateScrollPos

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

Source from the content-addressed store, hash-verified

2721 }
2722
2723 function calculateScrollPos(cm, x1, y1, x2, y2) {
2724 var display = cm.display, snapMargin = textHeight(cm.display);
2725 if (y1 < 0) y1 = 0;
2726 var screen = display.scroller.clientHeight - scrollerCutOff, screentop = display.scroller.scrollTop, result = {};
2727 var docBottom = cm.doc.height + paddingVert(display);
2728 var atTop = y1 < snapMargin, atBottom = y2 > docBottom - snapMargin;
2729 if (y1 < screentop) {
2730 result.scrollTop = atTop ? 0 : y1;
2731 } else if (y2 > screentop + screen) {
2732 var newTop = Math.min(y1, (atBottom ? docBottom : y2) - screen);
2733 if (newTop != screentop) result.scrollTop = newTop;
2734 }
2735
2736 var screenw = display.scroller.clientWidth - scrollerCutOff, screenleft = display.scroller.scrollLeft;
2737 x1 += display.gutters.offsetWidth; x2 += display.gutters.offsetWidth;
2738 var gutterw = display.gutters.offsetWidth;
2739 var atLeft = x1 < gutterw + 10;
2740 if (x1 < screenleft + gutterw || atLeft) {
2741 if (atLeft) x1 = 0;
2742 result.scrollLeft = Math.max(0, x1 - 10 - gutterw);
2743 } else if (x2 > screenw + screenleft - 3) {
2744 result.scrollLeft = x2 + 10 - screenw;
2745 }
2746 return result;
2747 }
2748
2749 function updateScrollPos(cm, left, top) {
2750 cm.curOp.updateScrollPos = {scrollLeft: left == null ? cm.doc.scrollLeft : left,

Callers 4

endOperationFunction · 0.70
scrollPosIntoViewFunction · 0.70
scrollIntoViewFunction · 0.70
codemirror.jsFile · 0.70

Calls 2

textHeightFunction · 0.70
paddingVertFunction · 0.70

Tested by

no test coverage detected