5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], mod);
11
})(function(CodeMirror) {
14
CodeMirror.defineOption("selectionPointer", false, function(cm, val) {
15
var data = cm.state.selectionPointer;
17
CodeMirror.off(cm.getWrapperElement(), "mousemove", data.mousemove);
18
CodeMirror.off(cm.getWrapperElement(), "mouseout", data.mouseout);
19
CodeMirror.off(window, "scroll", data.windowScroll);
20
cm.off("cursorActivity", reset);
21
cm.off("scroll", reset);
22
cm.state.selectionPointer = null;
23
cm.display.lineDiv.style.cursor = "";
26
data = cm.state.selectionPointer = {
27
value: typeof val == "string" ? val : "default",
28
mousemove: function(event) { mousemove(cm, event); },
29
mouseout: function(event) { mouseout(cm, event); },
30
windowScroll: function() { reset(cm); },
32
mouseX: null, mouseY: null,
35
CodeMirror.on(cm.getWrapperElement(), "mousemove", data.mousemove);
36
CodeMirror.on(cm.getWrapperElement(), "mouseout", data.mouseout);
37
CodeMirror.on(window, "scroll", data.windowScroll);
38
cm.on("cursorActivity", reset);
39
cm.on("scroll", reset);
43
function mousemove(cm, event) {
44
var data = cm.state.selectionPointer;
45
if (event.buttons == null ? event.which : event.buttons) {
46
data.mouseX = data.mouseY = null;
48
data.mouseX = event.clientX;
49
data.mouseY = event.clientY;
54
function mouseout(cm, event) {
55
if (!cm.getWrapperElement().contains(event.relatedTarget)) {
56
var data = cm.state.selectionPointer;
57
data.mouseX = data.mouseY = null;
63
cm.state.selectionPointer.rects = null;
67
function scheduleUpdate(cm) {
68
if (!cm.state.selectionPointer.willUpdate) {
69
cm.state.selectionPointer.willUpdate = true;
70
setTimeout(function() {
72
cm.state.selectionPointer.willUpdate = false;
78
var data = cm.state.selectionPointer;
80
if (data.rects == null && data.mouseX != null) {
82
if (cm.somethingSelected()) {
83
for (var sel = cm.display.selectionDiv.firstChild; sel; sel = sel.nextSibling)
84
data.rects.push(sel.getBoundingClientRect());
88
if (data.mouseX != null) for (var i = 0; i < data.rects.length; i++) {
89
var rect = data.rects[i];
90
if (rect.left <= data.mouseX && rect.right >= data.mouseX &&
91
rect.top <= data.mouseY && rect.bottom >= data.mouseY)
94
var cursor = inside ? data.value : "";
95
if (cm.display.lineDiv.style.cursor != cursor)
96
cm.display.lineDiv.style.cursor = cursor;