Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change font for the CodeMirror editor

I am trying to change font-family and font-size of my CodeMirror editor. I tried changing it by setting the according CSS attributes but it does not seem to work for me:

.codemirror-textarea {
    font-family: Arial, monospace;
    font-size: 16px;
}

Do I have to import something in order to achieve this or might I have to edit the libraries CSS file directly? What am I doing wrong?

like image 434
nullmn Avatar asked Dec 07 '17 14:12

nullmn


People also ask

How do I change font size in CodeMirror?

Step 2: JavaScript code to dynamically set the font size.CodeMirror-line span'). css('font-size',v + 'px') }); Update 12/07/2022: The above code will increase the font size, but the line will revert to its original font size when edited (I mean, the active line).

How do I change font size in editor?

Use a keyboard shortcut to change the font size in the editor. To increase the font size, press ⌃⇧Period on macOS or Alt+Shift+Dot on Windows and Linux. To decrease it, press ⌃⇧Comma on macOS or Alt+Shift+Comma on Windows and Linux.


2 Answers

Or add an extension

const customTheme = EditorView.theme({
    '&': {
        font:"'JetBrains Mono', monospace",
    }
})

const startState = EditorState.create({
    doc: page.text,
    extensions: [
        customTheme,
        // ...
    ]
})
like image 160

Try setting the CSS on:

.CodeMirror {
font-family: Arial, monospace;
font-size: 16px;
}

This selects the element that contains all the formatted code.

like image 36
SWC Avatar answered Nov 16 '22 01:11

SWC