Codemirror 6: reference to EditorView from EditorState

Hi @marijn, I’m trying to build a history extension for managing one history across multiple editor instances. My plan is to wrap some of the functions from the basic History module so that whenever an editor is updated, that editor is added to a list. And then on undo and redo, I track where I am in that list and call the undo or redo for that editor. The problem I’m having is that I need to be able to store a reference to the EditorView in the combined history list, but I can’t seem to be able to get a reference to the EditorView from any of the functions responsible for creating the history state or from the editor state.

Is there a best way to get a reference to the EditorState? Or am I going about this all wrong?

This might work better at a level above the view/state, since it needs to orchestrate between multiple views.

The editor state intentionally lives in its own ‘world’, away from the view, so there is no function that takes a state and returns a view. But you can pass in something like a view getter function when creating a state, and arrange things so that that gets access to the view when one has been created.

1 Like

Okay, interesting. So I would need to create an extension with a StateField that contains a reference to the view? Something like that? What might that look like?

I figured out how to give the state a facet that I can populate with a reference to the view. This seems to be working so far. Thanks @marijn!