Focusing the codemirror removes all the added classes


I am trying to add mobile support for my Vite app which uses Codemirror 6. To do this I check the screen size and when it is small, I add a class called “mobile” to my codemirror. Now, when I focus the codemirror, all its classes return to normal, leaving it as in the computer version. Is this a bug or my mistake? Greetings!


This is intentional. Use the editorAttributes facet to add classes – anything else will be overwritten by the library.

Hi marijn!

I’m sorry, but I could not understand the facets and how to do this. Could you leave me an example, please? Greeting!


Oh, I have tried using this code as an extension for testing but it didn’t work.


You’ll want to do something like EditorView.editorAttributes.of({class: "mobile"}) instead.

Yeah! That worked. Thank you!