Read-only editor still changeable?

I would like a simple read-only editor. It knows it’s read-only from the get-go. In many places, I saw a recommendation to include EditorState.readOnly.of(true) in the list of extensions. But when I do that, at least the view remains editable, which I find thoroughly weird. This “try” snippet demonstrates the issue:

https://codemirror.net/try/?c=aW1wb3J0IHsgRWRpdG9yU3RhdGUgfSBmcm9tICdAY29kZW1pcnJvci9zdGF0ZSc7CmltcG9ydCB7YmFzaWNTZXR1cCwgRWRpdG9yVmlld30gZnJvbSAiY29kZW1pcnJvciIKCm5ldyBFZGl0b3JWaWV3KHsKICBkb2M6ICIuLi4iLAogIGV4dGVuc2lvbnM6IFsuLi5iYXNpY1NldHVwLCBFZGl0b3JTdGF0ZS5yZWFkT25seS5vZih0cnVlKV0sCiAgcGFyZW50OiBkb2N1bWVudC5ib2R5Cn0pCg==

Only once I also add EditorView.editable.of(false) as well do I get the desired effect, which makes me think that there’s something I’m not understanding correctly. Any clarification would be much appreciated.

Thanks!

As an additional curious observation/apparent inconsistency, when using GitHub - replit/codemirror-vim: Vim keybindings for CM6, only setting the state to read-only seems to do the trick.

You’re seeing issue #1411. I’ll tag a release later today with the fix.

1 Like