LaravelTest
98 строк · 3.2 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineOption("selectionPointer", false, function(cm, val) {15var data = cm.state.selectionPointer;16if (data) {17CodeMirror.off(cm.getWrapperElement(), "mousemove", data.mousemove);18CodeMirror.off(cm.getWrapperElement(), "mouseout", data.mouseout);19CodeMirror.off(window, "scroll", data.windowScroll);20cm.off("cursorActivity", reset);21cm.off("scroll", reset);22cm.state.selectionPointer = null;23cm.display.lineDiv.style.cursor = "";24}25if (val) {26data = cm.state.selectionPointer = {27value: typeof val == "string" ? val : "default",28mousemove: function(event) { mousemove(cm, event); },29mouseout: function(event) { mouseout(cm, event); },30windowScroll: function() { reset(cm); },31rects: null,32mouseX: null, mouseY: null,33willUpdate: false34};35CodeMirror.on(cm.getWrapperElement(), "mousemove", data.mousemove);36CodeMirror.on(cm.getWrapperElement(), "mouseout", data.mouseout);37CodeMirror.on(window, "scroll", data.windowScroll);38cm.on("cursorActivity", reset);39cm.on("scroll", reset);40}41});42
43function mousemove(cm, event) {44var data = cm.state.selectionPointer;45if (event.buttons == null ? event.which : event.buttons) {46data.mouseX = data.mouseY = null;47} else {48data.mouseX = event.clientX;49data.mouseY = event.clientY;50}51scheduleUpdate(cm);52}53
54function mouseout(cm, event) {55if (!cm.getWrapperElement().contains(event.relatedTarget)) {56var data = cm.state.selectionPointer;57data.mouseX = data.mouseY = null;58scheduleUpdate(cm);59}60}61
62function reset(cm) {63cm.state.selectionPointer.rects = null;64scheduleUpdate(cm);65}66
67function scheduleUpdate(cm) {68if (!cm.state.selectionPointer.willUpdate) {69cm.state.selectionPointer.willUpdate = true;70setTimeout(function() {71update(cm);72cm.state.selectionPointer.willUpdate = false;73}, 50);74}75}76
77function update(cm) {78var data = cm.state.selectionPointer;79if (!data) return;80if (data.rects == null && data.mouseX != null) {81data.rects = [];82if (cm.somethingSelected()) {83for (var sel = cm.display.selectionDiv.firstChild; sel; sel = sel.nextSibling)84data.rects.push(sel.getBoundingClientRect());85}86}87var inside = false;88if (data.mouseX != null) for (var i = 0; i < data.rects.length; i++) {89var rect = data.rects[i];90if (rect.left <= data.mouseX && rect.right >= data.mouseX &&91rect.top <= data.mouseY && rect.bottom >= data.mouseY)92inside = true;93}94var cursor = inside ? data.value : "";95if (cm.display.lineDiv.style.cursor != cursor)96cm.display.lineDiv.style.cursor = cursor;97}98});99