MCPcopy
hub / github.com/csev/py4e / registerEventHandlers

Function registerEventHandlers

tools/pythonauto/static/codemirrorepl/codemirror.js:2318–2453  ·  view source on GitHub ↗
(cm)

Source from the content-addressed store, hash-verified

2316
2317 // Attach the necessary event handlers when initializing the editor
2318 function registerEventHandlers(cm) {
2319 var d = cm.display;
2320 on(d.scroller, "mousedown", operation(cm, onMouseDown));
2321 // Older IE's will not fire a second mousedown for a double click
2322 if (ie_upto10)
2323 on(d.scroller, "dblclick", operation(cm, function(e) {
2324 if (signalDOMEvent(cm, e)) return;
2325 var pos = posFromMouse(cm, e);
2326 if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) return;
2327 e_preventDefault(e);
2328 var word = findWordAt(cm.doc, pos);
2329 extendSelection(cm.doc, word.anchor, word.head);
2330 }));
2331 else
2332 on(d.scroller, "dblclick", function(e) { signalDOMEvent(cm, e) || e_preventDefault(e); });
2333 // Prevent normal selection in the editor (we handle our own)
2334 on(d.lineSpace, "selectstart", function(e) {
2335 if (!eventInWidget(d, e)) e_preventDefault(e);
2336 });
2337 // Some browsers fire contextmenu *after* opening the menu, at
2338 // which point we can't mess with it anymore. Context menu is
2339 // handled in onMouseDown for these browsers.
2340 if (!captureRightClick) on(d.scroller, "contextmenu", function(e) {onContextMenu(cm, e);});
2341
2342 // Sync scrolling between fake scrollbars and real scrollable
2343 // area, ensure viewport is updated when scrolling.
2344 on(d.scroller, "scroll", function() {
2345 if (d.scroller.clientHeight) {
2346 setScrollTop(cm, d.scroller.scrollTop);
2347 setScrollLeft(cm, d.scroller.scrollLeft, true);
2348 signal(cm, "scroll", cm);
2349 }
2350 });
2351 on(d.scrollbarV, "scroll", function() {
2352 if (d.scroller.clientHeight) setScrollTop(cm, d.scrollbarV.scrollTop);
2353 });
2354 on(d.scrollbarH, "scroll", function() {
2355 if (d.scroller.clientHeight) setScrollLeft(cm, d.scrollbarH.scrollLeft);
2356 });
2357
2358 // Listen to wheel events in order to try and update the viewport on time.
2359 on(d.scroller, "mousewheel", function(e){onScrollWheel(cm, e);});
2360 on(d.scroller, "DOMMouseScroll", function(e){onScrollWheel(cm, e);});
2361
2362 // Prevent clicks in the scrollbars from killing focus
2363 function reFocus() { if (cm.state.focused) setTimeout(bind(focusInput, cm), 0); }
2364 on(d.scrollbarH, "mousedown", reFocus);
2365 on(d.scrollbarV, "mousedown", reFocus);
2366 // Prevent wrapper from ever scrolling
2367 on(d.wrapper, "scroll", function() { d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; });
2368
2369 // When the window resizes, we need to refresh active editors.
2370 var resizeTimer;
2371 function onResize() {
2372 if (resizeTimer == null) resizeTimer = setTimeout(function() {
2373 resizeTimer = null;
2374 // Might be a text scaling operation, clear size caches.
2375 d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = knownScrollbarWidth = null;

Callers 1

CodeMirrorFunction · 0.70

Calls 15

onFunction · 0.85
signalFunction · 0.85
activeEltFunction · 0.85
operationFunction · 0.70
signalDOMEventFunction · 0.70
posFromMouseFunction · 0.70
clickInGutterFunction · 0.70
eventInWidgetFunction · 0.70
e_preventDefaultFunction · 0.70
findWordAtFunction · 0.70
extendSelectionFunction · 0.70
onContextMenuFunction · 0.70

Tested by

no test coverage detected