Search code examples
codemirror

How to disable highlight active line in codemirror when editor is not selected?


I only want to have active line on when the current code editor is selected. How would I set this on editor initialisation?


Solution

  • Use .CodeMirror-focused class, so that the line is only styled when the cursor is focused within the editor. Then make the normal .CodeMirror-activeline-background transparent so that when the cursor is not focused within the editor, it will not be styled.

    .CodeMirror-activeline-background {
        background: transparent !important;
    }
    .CodeMirror-focused .CodeMirror-activeline-background {
        background: rgba(100, 100, 100, 0.1) !important;
    }