MCPcopy Create free account
hub / github.com/sql-js/sql.js / registerEventHandlers

Function registerEventHandlers

GUI/codemirror/lib/codemirror.js:2338–2483  ·  view source on GitHub ↗
(cm)

Source from the content-addressed store, hash-verified

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

Callers 1

CodeMirrorFunction · 0.85

Calls 15

operationFunction · 0.85
signalDOMEventFunction · 0.85
posFromMouseFunction · 0.85
clickInGutterFunction · 0.85
eventInWidgetFunction · 0.85
findWordAtFunction · 0.85
extendSelectionFunction · 0.85
onContextMenuFunction · 0.85
setScrollTopFunction · 0.85
setScrollLeftFunction · 0.85
onScrollWheelFunction · 0.85
fastPollFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…