**Background**
[r1322513](https://gerrit.wikimedia.org/r/c/mediawiki/extensions/CodeMirror/+/1322513) adds a new reusable Vue component for a CodeMirror editor. This works great but to fully satisfy WikiLambda's needs (T400015), we need `readonly` as a Vue prop, meaning it can change during an editing session. Currently, the core [CodeMirror class](https://doc.wikimedia.org/CodeMirror/master/js/js/CodeMirror.html) checks the `readonly` property of the textarea only //once//, meaning we need to rebuild the entire editor if a client wants to change the read-only state.
Overall this is [not deemed a major issue](https://gerrit.wikimedia.org/r/c/mediawiki/extensions/CodeMirror/+/1322513/comment/fe0166d4_7ec8ef7b/), as if it comes down to it, the editor can simply be re-created when the `readonly` prop changes.
**Proposed solution**
Let's rework [CodeMirror#readOnly](https://doc.wikimedia.org/CodeMirror/master/js/js/CodeMirror.html#readOnly) to be a [compartment](https://codemirror.net/examples/config/#compartments). Conveniently most functionality that comes with or without read-only is already an [Extension](https://codemirror.net/docs/ref/#state.Extension), so that can easily be encompassed within the `readOnly` compartment.
The only thing that gives me pause is [applyLinter()](https://doc.wikimedia.org/CodeMirror/master/js/js/CodeMirror.html#applyLinter) checks the read-only state as well when constructing it's Extension, and that is called arbitrarily at any point after initialization. So, if the read-only state changes, the linter must be re-applied or else the "quick-fix" actions won't be available. `applyLinter()` currently isn't used internally and meant only for integrations such as gadgets and user scripts, so there's some freedom on what we can do here. I'm thinking either:
1. Add a new JS hook for when the read-only state changes, so clients can react accordingly, or
1. Add a transaction listener in [CodeMirrorLint](https://doc.wikimedia.org/CodeMirror/master/js/js/CodeMirrorLint.html) so that it automatically reacts and adds or removes the diagnostic actions ("quick-fix").
#2 is surely best but I'll need to do further exploration before I can conclude this is feasible.