(cm)
| 10878 | |
| 10879 | // Attach the necessary event handlers when initializing the editor |
| 10880 | function registerEventHandlers(cm) { |
| 10881 | var d = cm.display |
| 10882 | on(d.scroller, "mousedown", operation(cm, onMouseDown)) |
| 10883 | // Older IE's will not fire a second mousedown for a double click |
| 10884 | if (ie && ie_version < 11) { |
| 10885 | on( |
| 10886 | d.scroller, |
| 10887 | "dblclick", |
| 10888 | operation(cm, function (e) { |
| 10889 | if (signalDOMEvent(cm, e)) { |
| 10890 | return |
| 10891 | } |
| 10892 | var pos = posFromMouse(cm, e) |
| 10893 | if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) { |
| 10894 | return |
| 10895 | } |
| 10896 | e_preventDefault(e) |
| 10897 | var word = cm.findAtomAt(pos) |
| 10898 | extendSelection(cm.doc, word.anchor, word.head) |
| 10899 | }) |
| 10900 | ) |
| 10901 | } else { |
| 10902 | on(d.scroller, "dblclick", function (e) { |
| 10903 | return signalDOMEvent(cm, e) || e_preventDefault(e) |
| 10904 | }) |
| 10905 | } |
| 10906 | // Some browsers fire contextmenu *after* opening the menu, at |
| 10907 | // which point we can't mess with it anymore. Context menu is |
| 10908 | // handled in onMouseDown for these browsers. |
| 10909 | on(d.scroller, "contextmenu", function (e) { |
| 10910 | return onContextMenu(cm, e) |
| 10911 | }) |
| 10912 | |
| 10913 | // Used to suppress mouse event handling when a touch happens |
| 10914 | var touchFinished, |
| 10915 | prevTouch = { end: 0 } |
| 10916 | function finishTouch() { |
| 10917 | if (d.activeTouch) { |
| 10918 | touchFinished = setTimeout(function () { |
| 10919 | return (d.activeTouch = null) |
| 10920 | }, 1000) |
| 10921 | prevTouch = d.activeTouch |
| 10922 | prevTouch.end = +new Date() |
| 10923 | } |
| 10924 | } |
| 10925 | function isMouseLikeTouchEvent(e) { |
| 10926 | if (e.touches.length != 1) { |
| 10927 | return false |
| 10928 | } |
| 10929 | var touch = e.touches[0] |
| 10930 | return touch.radiusX <= 1 && touch.radiusY <= 1 |
| 10931 | } |
| 10932 | function farAway(touch, other) { |
| 10933 | if (other.left == null) { |
| 10934 | return true |
| 10935 | } |
| 10936 | var dx = other.left - touch.left, |
| 10937 | dy = other.top - touch.top |
no test coverage detected