View passed to keymap handler

I initialize a state with a KeyMap:

let editState = EditorState.create({ ... "Mod-z": (state, dispatch, view) => { console.log(view) ; }

Then a view with that state:

let view = new MenuBarEditorView(document.querySelector("#editor"), ...

But in Mod-z handler, view is of type EditorView and not MenuBarEditorView

why ?


A menu bar view wraps a regular editor view, it doesn’t extend it, so they can’t be used in place of an editor view.

I might see if I can rewrite menubareditorview as a plugin, now that we have plugin views, to prevent this kind of confusion.

plugin views are good when the plugin needs to respond to view changes but not when a plugin want to change the view (for example a search and replace plugin doing a replace). How should such a case be handled ?

Could you be a little more specific? What is difficult about dispatching a transaction from a plugin view?

perhaps I’m missing the obvious but

How does a plugin updates the view ?

The only mechanism I see ATM is the view in PluginSpec :slight_smile:

view(EditorView) → Object

When the plugin needs to interact with the editor view, or set something up in the DOM, use this field. The function will be called when the plugin’s state is associated with an editor view.

returns: Object Should return an object with the following optional properties: update(view: EditorView, prevState: EditorState) Called whenever the view’s state is updated. destroy() Called when the view is destroyed or receives a state with different plugins.

How is this used ? any example ? how to handle a case when the plugin want to update the view in response to some user interaction on some widget the plugin created ? (ie S&R)

in that case update above is not called so how does the plugin get the view ?

Again apologies if this is a total misunderstanding …

It’d store a reference to the view and call dispatch on that.

you mean store a reference from the view parameter of update above the first time it is called ?

yes that’ll work though it means the plugin cannot modify the view before update is called at least once.

The plugin’s view method is called with the editor view as argument immediately when the editor view is created, so you store that reference.

got it, thx! would be great to make the docs clearer on that

The intention is to go through some examples for stuff like this in the guide, eventually

(I’ve made the menubar a regular plugin in the repositories.)