1 // Because sometimes you need to style the cursor's line.
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".
9 var WRAP_CLASS = "CodeMirror-activeline";
10 var BACK_CLASS = "CodeMirror-activeline-background";
12 CodeMirror.defineOption("styleActiveLine", false, function(cm, val, old) {
13 var prev = old && old != CodeMirror.Init;
16 cm.on("cursorActivity", updateActiveLine);
17 } else if (!val && prev) {
18 cm.off("cursorActivity", updateActiveLine);
20 delete cm.state.activeLine;
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);
31 function updateActiveLine(cm) {
32 var line = cm.getLineHandleVisualStart(cm.getCursor().line);
33 if (cm.state.activeLine == line) return;
35 cm.addLineClass(line, "wrap", WRAP_CLASS);
36 cm.addLineClass(line, "background", BACK_CLASS);
37 cm.state.activeLine = line;