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

Function calculateScrollPos

static/editor.md/lib/codemirror/lib/codemirror.js:4458–4484  ·  view source on GitHub ↗
(cm, x1, y1, x2, y2)

Source from the content-addressed store, hash-verified

4456 // scrollLeft properties. When these are undefined, the
4457 // vertical/horizontal position does not need to be adjusted.
4458 function calculateScrollPos(cm, x1, y1, x2, y2) {
4459 var display = cm.display, snapMargin = textHeight(cm.display);
4460 if (y1 < 0) y1 = 0;
4461 var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;
4462 var screen = displayHeight(cm), result = {};
4463 if (y2 - y1 > screen) y2 = y1 + screen;
4464 var docBottom = cm.doc.height + paddingVert(display);
4465 var atTop = y1 < snapMargin, atBottom = y2 > docBottom - snapMargin;
4466 if (y1 < screentop) {
4467 result.scrollTop = atTop ? 0 : y1;
4468 } else if (y2 > screentop + screen) {
4469 var newTop = Math.min(y1, (atBottom ? docBottom : y2) - screen);
4470 if (newTop != screentop) result.scrollTop = newTop;
4471 }
4472
4473 var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;
4474 var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0);
4475 var tooWide = x2 - x1 > screenw;
4476 if (tooWide) x2 = x1 + screenw;
4477 if (x1 < 10)
4478 result.scrollLeft = 0;
4479 else if (x1 < screenleft)
4480 result.scrollLeft = Math.max(0, x1 - (tooWide ? 0 : 10));
4481 else if (x2 > screenw + screenleft - 3)
4482 result.scrollLeft = x2 + (tooWide ? 0 : 10) - screenw;
4483 return result;
4484 }
4485
4486 // Store a relative adjustment to the scroll position in the current
4487 // 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