Best way to get latest `state` during editing?

handleTextInput From doc:

handleTextInput(view: EditorView, from: number, to: number, text: string) → bool Whenever the user directly input text, this handler is called before the input is applied. If it returns true , the default effect of actually inserting the text is suppressed.

I want to get the lastest json representation of editor state right after all the input(or drop, paste) is applied.

I only find a workaround by accessing lastest state in setTimeout which is tidious because it should also be put inside handlePaste, handleDrop, etc.

        const view = new EditorView(editorElement, {
          handleTextInput: (view, from, to, text) => {
             setTimeout(() => {
               // access to view after input is applied

resolved, should use dispatchtransaction

1 Like