Hej,
I am running into kind of conundrum and want to stick as much to the optimal update flow as possible based on what CodeMirror does during an update. I’ve read and re-read the documentation and this forum for the past week to no avail.
For context, I have an extension, implemented as a StateField
that provides a set of BlockWidget
type Decoration.replace
ments. These are quite expensive to calculate, so I already adapted the StateField
s update()
method in such a way that I only actually create the new decorations/map existing decoration ranges as I need them.
However, I need the widgets to update, preferably with a function I control to keep the actual DOM updates as cheap as possible, and it appears to me as if the updateDOM
function is never called on Block level widgets. Is this true? If so, what would be an appropriate place to let them update? The reason I’m asking is that, while I can actually update the DOM structure manually during the state update (in which Block level widgets, I think, can still be updated), they need a reference to the EditorView
at some point. The reason is that they may, if the main selection range is within them, need to show a sub-EditorView (akin to the split view example) that gets hooked to receiving updates from the main view. This will happen outside the main view’s update cycle so that there’s no interference in the DOM writing stage. I have already thought about the following possibilities:
- Create a ViewPlugin in the
provide
function that calls the function manually during an update cycle. (But then this might change the editor height, so the function should really be called before the DOM update after which, I presume, the ViewPlugins will be updated?) - Let the
toDOM
function in the widgets cache a reference to theEditorView
, and call a custom function on the widgets during the state update. Since the widgets are bound to one specific view, this should be fine, no? It sounds reasonable, but feels very dirty to me – especially since there is theupdateDOM
function, and it feels wrong not to use it. - Are there maybe other ways that I haven’t thought about?
So I have essentially two questions:
- What exactly is the update cycle of CodeMirror? When does what get executed? (This might actually be valuable information on the main page, next to the event → state update → view update cycle diagram.)
- How should I approach this problem?
Sorry for the lengthy post, but I hope that you may be able to help me out here.
Thanks already in advance!