Skip to content
Snippets Groups Projects
Commit 48d11dad authored by Marijn Haverbeke's avatar Marijn Haverbeke
Browse files

[activeline addon] Optimize

Issue #2007
parent 38321d43
No related branches found
No related tags found
Loading
......@@ -12,10 +12,10 @@
CodeMirror.defineOption("styleActiveLine", false, function(cm, val, old) {
var prev = old && old != CodeMirror.Init;
if (val && !prev) {
updateActiveLine(cm);
cm.on("cursorActivity", updateActiveLine);
updateActiveLine(cm, cm.getCursor().line);
cm.on("beforeSelectionChange", selectionChange);
} else if (!val && prev) {
cm.off("cursorActivity", updateActiveLine);
cm.off("beforeSelecionChange", selectionChange);
clearActiveLine(cm);
delete cm.state.activeLine;
}
......@@ -28,12 +28,18 @@
}
}
function updateActiveLine(cm) {
var line = cm.getLineHandleVisualStart(cm.getCursor().line);
function updateActiveLine(cm, selectedLine) {
var line = cm.getLineHandleVisualStart(selectedLine);
if (cm.state.activeLine == line) return;
clearActiveLine(cm);
cm.addLineClass(line, "wrap", WRAP_CLASS);
cm.addLineClass(line, "background", BACK_CLASS);
cm.state.activeLine = line;
cm.operation(function() {
clearActiveLine(cm);
cm.addLineClass(line, "wrap", WRAP_CLASS);
cm.addLineClass(line, "background", BACK_CLASS);
cm.state.activeLine = line;
});
}
function selectionChange(cm, sel) {
updateActiveLine(cm, sel.head.line);
}
})();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment