View without editing


I am trying to develop a tool for annotating documents, I feel that the full editor would be a bit of an overkill for this project. I was considering using the @codemirror/text, @codemirror/rangeset and @codemirror/state libraries to keep track of the annotaions and decorations. However, I’m a bit stuck on how to create a readonly view from it. Is this possible and would you recommend it?

All I want is the mapping (state) => html without the editing features (possibly handling selection ranges).

Thank you!

The rendering code is very closely tied to the view, so either you can create a readonly view (with an EditorView.editable.of(false) extension), or you can write your own rendering logic, but if you want things like syntax highlighting that might be quite a lot of duplicated work.

I will not be needing syntax highlighting (as long as mark decorations are supported) since I plan on having only “plain text” documents with annotations around some ranges.

I decided to go with the EditorView.editable.of(false) strategy. :slight_smile:

Thank you!