benrbray / prosemirror-math

Schema and plugins for "first-class" math support in ProseMirror!
https://benrbray.com/prosemirror-math/
MIT License
245 stars 35 forks source link

Add support for readOnly mode #24

Closed Saul-Mirone closed 3 years ago

Saul-Mirone commented 3 years ago

23

Saul-Mirone commented 3 years ago

A gentle ping... @benrbray

benrbray commented 3 years ago

Thanks for the PR! And my apologies for the very late review. I cloned your branch, but unfortunately I wasn't able to replicate the desired read-only behavior with your change. Would you be able to explain how to set up a read-only editor using this change?

In particular, I tried setting the editor DOM element's contentEditable="false" as well as setting EditorView.editable = false. In both cases, the ProseMirror editor was still active and in the MathView.selectNode() function, this._outerEditor.editable was logged as true.

Saul-Mirone commented 3 years ago

Thanks for the PR! And my apologies for the very late review. I cloned your branch, but unfortunately I wasn't able to replicate the desired read-only behavior with your change. Would you be able to explain how to set up a read-only editor using this change?

In particular, I tried setting the editor DOM element's contentEditable="false" as well as setting EditorView.editable = false. In both cases, the ProseMirror editor was still active and in the MathView.selectNode() function, this._outerEditor.editable was logged as true.

Hi Benrbray, thanks for reviewing, according to this document, it seems that you should do this to enable the readOnly mode:

let view = new EditorView({
  state: myState,
  editable() { return false }, // Enables read-only behavior
})
Saul-Mirone commented 3 years ago

BTW, you can also find this example in prosemirror's official guide image

Saul-Mirone commented 3 years ago

Another gentle ping... @benrbray

benrbray commented 3 years ago

Everything seems to work OK, I'll merge and publish a new npm version. Thanks for the PR!