Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/addon/selection/active-line.js
1294 views
// Because sometimes you need to style the cursor's line.1//2// Adds an option 'styleActiveLine' which, when enabled, gives the3// active line's wrapping <div> the CSS class "CodeMirror-activeline",4// and gives its background <div> the class "CodeMirror-activeline-background".56(function() {7"use strict";8var WRAP_CLASS = "CodeMirror-activeline";9var BACK_CLASS = "CodeMirror-activeline-background";1011CodeMirror.defineOption("styleActiveLine", false, function(cm, val, old) {12var prev = old && old != CodeMirror.Init;13if (val && !prev) {14updateActiveLine(cm, cm.getCursor().line);15cm.on("beforeSelectionChange", selectionChange);16} else if (!val && prev) {17cm.off("beforeSelectionChange", selectionChange);18clearActiveLine(cm);19delete cm.state.activeLine;20}21});2223function clearActiveLine(cm) {24if ("activeLine" in cm.state) {25cm.removeLineClass(cm.state.activeLine, "wrap", WRAP_CLASS);26cm.removeLineClass(cm.state.activeLine, "background", BACK_CLASS);27}28}2930function updateActiveLine(cm, selectedLine) {31var line = cm.getLineHandleVisualStart(selectedLine);32if (cm.state.activeLine == line) return;33cm.operation(function() {34clearActiveLine(cm);35cm.addLineClass(line, "wrap", WRAP_CLASS);36cm.addLineClass(line, "background", BACK_CLASS);37cm.state.activeLine = line;38});39}4041function selectionChange(cm, sel) {42updateActiveLine(cm, sel.head.line);43}44})();454647