Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/addon/selection/active-line.js
1294 views
1
// Because sometimes you need to style the cursor's line.
2
//
3
// Adds an option 'styleActiveLine' which, when enabled, gives the
4
// active line's wrapping <div> the CSS class "CodeMirror-activeline",
5
// and gives its background <div> the class "CodeMirror-activeline-background".
6
7
(function() {
8
"use strict";
9
var WRAP_CLASS = "CodeMirror-activeline";
10
var BACK_CLASS = "CodeMirror-activeline-background";
11
12
CodeMirror.defineOption("styleActiveLine", false, function(cm, val, old) {
13
var prev = old && old != CodeMirror.Init;
14
if (val && !prev) {
15
updateActiveLine(cm, cm.getCursor().line);
16
cm.on("beforeSelectionChange", selectionChange);
17
} else if (!val && prev) {
18
cm.off("beforeSelectionChange", selectionChange);
19
clearActiveLine(cm);
20
delete cm.state.activeLine;
21
}
22
});
23
24
function clearActiveLine(cm) {
25
if ("activeLine" in cm.state) {
26
cm.removeLineClass(cm.state.activeLine, "wrap", WRAP_CLASS);
27
cm.removeLineClass(cm.state.activeLine, "background", BACK_CLASS);
28
}
29
}
30
31
function updateActiveLine(cm, selectedLine) {
32
var line = cm.getLineHandleVisualStart(selectedLine);
33
if (cm.state.activeLine == line) return;
34
cm.operation(function() {
35
clearActiveLine(cm);
36
cm.addLineClass(line, "wrap", WRAP_CLASS);
37
cm.addLineClass(line, "background", BACK_CLASS);
38
cm.state.activeLine = line;
39
});
40
}
41
42
function selectionChange(cm, sel) {
43
updateActiveLine(cm, sel.head.line);
44
}
45
})();
46
47