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

Function onScrollWheel

static/mergely/lib/codemirror.js:3998–4071  ·  view source on GitHub ↗
(cm, e)

Source from the content-addressed store, hash-verified

3996 };
3997
3998 function onScrollWheel(cm, e) {
3999 var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y;
4000
4001 var display = cm.display, scroll = display.scroller;
4002 // Quit if there's nothing to scroll here
4003 var canScrollX = scroll.scrollWidth > scroll.clientWidth;
4004 var canScrollY = scroll.scrollHeight > scroll.clientHeight;
4005 if (!(dx && canScrollX || dy && canScrollY)) return;
4006
4007 // Webkit browsers on OS X abort momentum scrolls when the target
4008 // of the scroll event is removed from the scrollable element.
4009 // This hack (see related code in patchDisplay) makes sure the
4010 // element is kept around.
4011 if (dy && mac && webkit) {
4012 outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
4013 for (var i = 0; i < view.length; i++) {
4014 if (view[i].node == cur) {
4015 cm.display.currentWheelTarget = cur;
4016 break outer;
4017 }
4018 }
4019 }
4020 }
4021
4022 // On some browsers, horizontal scrolling will cause redraws to
4023 // happen before the gutter has been realigned, causing it to
4024 // wriggle around in a most unseemly way. When we have an
4025 // estimated pixels/delta value, we just handle horizontal
4026 // scrolling entirely here. It'll be slightly off from native, but
4027 // better than glitching out.
4028 if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
4029 if (dy && canScrollY)
4030 setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight)));
4031 setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)));
4032 // Only prevent default scrolling if vertical scrolling is
4033 // actually possible. Otherwise, it causes vertical scroll
4034 // jitter on OSX trackpads when deltaX is small and deltaY
4035 // is large (issue #3579)
4036 if (!dy || (dy && canScrollY))
4037 e_preventDefault(e);
4038 display.wheelStartX = null; // Abort measurement, if in progress
4039 return;
4040 }
4041
4042 // 'Project' the visible viewport to cover the area that is being
4043 // scrolled into view (if we know enough to estimate it).
4044 if (dy && wheelPixelsPerUnit != null) {
4045 var pixels = dy * wheelPixelsPerUnit;
4046 var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight;
4047 if (pixels < 0) top = Math.max(0, top + pixels - 50);
4048 else bot = Math.min(cm.doc.height, bot + pixels + 50);
4049 updateDisplaySimple(cm, {top: top, bottom: bot});
4050 }
4051
4052 if (wheelSamples < 20) {
4053 if (display.wheelStartX == null) {
4054 display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop;
4055 display.wheelDX = dx; display.wheelDY = dy;

Callers 1

registerEventHandlersFunction · 0.70

Calls 4

wheelEventDeltaFunction · 0.70
setScrollTopFunction · 0.70
setScrollLeftFunction · 0.70
updateDisplaySimpleFunction · 0.70

Tested by

no test coverage detected