I’m starting to work with CodeMirror 6 and am wondering if it’s possible, in a CM instance that is both not-editable and read-only, to create a Decoration that can be edited.
My use-case is that I am rendering read-only code samples for a documentation site, but would like to allow the user to set custom values within a sample (like an API key).
Currently I have a setup where, when a range is “editable” I create a mark decoration that wraps the content in a <button>
to make it look editable, and when the user clicks it the button hidden and a widget decoration that renders an <input type="text">
is inserted. The UX for this is nice but the implementation is tricky, because I have to manage various events on the input, communicate the new value to the original code sample, etc.
Is there a more straightforward way to make a substring editable in a non-editable CM instance? I was hoping I would be as simple as setting contenteditable
on the decoration, but something about that isn’t working either.