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

Function onScrollWheel

tools/pythonauto/static/codemirror/codemirror.js:2009–2075  ·  view source on GitHub ↗
(cm, e)

Source from the content-addressed store, hash-verified

2007 else if (safari) wheelPixelsPerUnit = -1/3;
2008
2009 function onScrollWheel(cm, e) {
2010 var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
2011 if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) dx = e.detail;
2012 if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) dy = e.detail;
2013 else if (dy == null) dy = e.wheelDelta;
2014
2015 var display = cm.display, scroll = display.scroller;
2016 // Quit if there's nothing to scroll here
2017 if (!(dx && scroll.scrollWidth > scroll.clientWidth ||
2018 dy && scroll.scrollHeight > scroll.clientHeight)) return;
2019
2020 // Webkit browsers on OS X abort momentum scrolls when the target
2021 // of the scroll event is removed from the scrollable element.
2022 // This hack (see related code in patchDisplay) makes sure the
2023 // element is kept around.
2024 if (dy && mac && webkit) {
2025 for (var cur = e.target; cur != scroll; cur = cur.parentNode) {
2026 if (cur.lineObj) {
2027 cm.display.currentWheelTarget = cur;
2028 break;
2029 }
2030 }
2031 }
2032
2033 // On some browsers, horizontal scrolling will cause redraws to
2034 // happen before the gutter has been realigned, causing it to
2035 // wriggle around in a most unseemly way. When we have an
2036 // estimated pixels/delta value, we just handle horizontal
2037 // scrolling entirely here. It'll be slightly off from native, but
2038 // better than glitching out.
2039 if (dx && !gecko && !opera && wheelPixelsPerUnit != null) {
2040 if (dy)
2041 setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight)));
2042 setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)));
2043 e_preventDefault(e);
2044 display.wheelStartX = null; // Abort measurement, if in progress
2045 return;
2046 }
2047
2048 if (dy && wheelPixelsPerUnit != null) {
2049 var pixels = dy * wheelPixelsPerUnit;
2050 var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight;
2051 if (pixels < 0) top = Math.max(0, top + pixels - 50);
2052 else bot = Math.min(cm.doc.height, bot + pixels + 50);
2053 updateDisplay(cm, [], {top: top, bottom: bot});
2054 }
2055
2056 if (wheelSamples < 20) {
2057 if (display.wheelStartX == null) {
2058 display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop;
2059 display.wheelDX = dx; display.wheelDY = dy;
2060 setTimeout(function() {
2061 if (display.wheelStartX == null) return;
2062 var movedX = scroll.scrollLeft - display.wheelStartX;
2063 var movedY = scroll.scrollTop - display.wheelStartY;
2064 var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
2065 (movedX && display.wheelDX && movedX / display.wheelDX);
2066 display.wheelStartX = display.wheelStartY = null;

Callers 1

registerEventHandlersFunction · 0.70

Calls 4

setScrollTopFunction · 0.70
setScrollLeftFunction · 0.70
e_preventDefaultFunction · 0.70
updateDisplayFunction · 0.70

Tested by

no test coverage detected