Fix: merge conflict
[myslice.git] / to-be-integrated / third-party / codemirror-3.15 / addon / selection / active-line.js
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);
16       cm.on("cursorActivity", updateActiveLine);
17     } else if (!val && prev) {
18       cm.off("cursorActivity", updateActiveLine);
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) {
32     var line = cm.getLineHandleVisualStart(cm.getCursor().line);
33     if (cm.state.activeLine == line) return;
34     clearActiveLine(cm);
35     cm.addLineClass(line, "wrap", WRAP_CLASS);
36     cm.addLineClass(line, "background", BACK_CLASS);
37     cm.state.activeLine = line;
38   }
39 })();