LaravelTest
72 строки · 2.4 Кб
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";13var WRAP_CLASS = "CodeMirror-activeline";14var BACK_CLASS = "CodeMirror-activeline-background";15var GUTT_CLASS = "CodeMirror-activeline-gutter";16
17CodeMirror.defineOption("styleActiveLine", false, function(cm, val, old) {18var prev = old == CodeMirror.Init ? false : old;19if (val == prev) return20if (prev) {21cm.off("beforeSelectionChange", selectionChange);22clearActiveLines(cm);23delete cm.state.activeLines;24}25if (val) {26cm.state.activeLines = [];27updateActiveLines(cm, cm.listSelections());28cm.on("beforeSelectionChange", selectionChange);29}30});31
32function clearActiveLines(cm) {33for (var i = 0; i < cm.state.activeLines.length; i++) {34cm.removeLineClass(cm.state.activeLines[i], "wrap", WRAP_CLASS);35cm.removeLineClass(cm.state.activeLines[i], "background", BACK_CLASS);36cm.removeLineClass(cm.state.activeLines[i], "gutter", GUTT_CLASS);37}38}39
40function sameArray(a, b) {41if (a.length != b.length) return false;42for (var i = 0; i < a.length; i++)43if (a[i] != b[i]) return false;44return true;45}46
47function updateActiveLines(cm, ranges) {48var active = [];49for (var i = 0; i < ranges.length; i++) {50var range = ranges[i];51var option = cm.getOption("styleActiveLine");52if (typeof option == "object" && option.nonEmpty ? range.anchor.line != range.head.line : !range.empty())53continue54var line = cm.getLineHandleVisualStart(range.head.line);55if (active[active.length - 1] != line) active.push(line);56}57if (sameArray(cm.state.activeLines, active)) return;58cm.operation(function() {59clearActiveLines(cm);60for (var i = 0; i < active.length; i++) {61cm.addLineClass(active[i], "wrap", WRAP_CLASS);62cm.addLineClass(active[i], "background", BACK_CLASS);63cm.addLineClass(active[i], "gutter", GUTT_CLASS);64}65cm.state.activeLines = active;66});67}68
69function selectionChange(cm, sel) {70updateActiveLines(cm, sel.ranges);71}72});73