codemirror / dev

Development repository for the CodeMirror editor project
https://codemirror.net/
Other
5.94k stars 377 forks source link

Setting `EditorView.editable.of(false)` does not work with EditContext API #1393

Closed jclem closed 5 months ago

jclem commented 5 months ago

Describe the issue

When using the EditContext API, EditorView.editable.of(false) has no effect, as it only disables contenteditable. There is no apparent solution for non-readonly non-editable editors when using the EditContext API.

Admittedly—this isn't breaking the behavior of EditorView.editable because the documentation for that is clear that it controls whether the DOM itself is editable...but I feel like that definition is still a little fuzzy maybe when EditContext is in the picture.

It's also worth noting that none of the documentation mentions the switch to the EditContext API, and this would only be visible to folks reading the changelog when upgrading versions. This took me a while to find, as I'm working on a new project. I wonder if the switch to the EditContext API should be considered a breaking change (or alternatively, it could be opt-in, instead), and perhaps there should be a more obvious (and TypeScript-friendly) way to disable CodeMirror's use of it—beyond the undocumented EDIT_CONTEXT property on EditorView.

Browser and platform

Chrome

Reproduction link

No response

marijnh commented 5 months ago

Attached patch should address this.

This took me a while to find, as I'm working on a new project. I wonder if the switch to the EditContext API should be considered a breaking change (or alternatively, it could be opt-in, instead)

There shouldn't be a lot of user-code visible changes in the way the control behaves. Did anything, beyond these bugs you reported, change in your integration?

jclem commented 5 months ago

lol So quick! As always, I am astounded at and thankful for your productivity and responsiveness. Thank you.

I haven't noticed anything else yet, but I'll keep an eye out. This is on a brand new integration (<1 hour), so this is all I've found so far.