How to manage history between prosemirror and Android native?

I integrated ProseMirror into the Android Application.Now, I want to put some Android native operations to prosemirror- history. For example, I have some doodle records that have their own undo, redo interface, and I can call certain TypeScript scripts while doodling, and at this point I need to add a custom record to the tiptap-history to mark this as a doodle operation, and then when prosemirror-history#undo, I want to be able to distinguishing between doodles and other editor operations

One way to do this would be to create a custom Step subclass that encodes these operations, and add dummy transactions with such steps to your editor when they occur. If you implement the step’s invert method right and listen to such steps being applied by history transactions, you may be able to get this to work.

how can I keep track of step changes in current editor? when I use editor.commands.undo, The callback is executed multiple times(console.log), and undo callback is also executed when I enter any text in the editor; This doesn’t seem to be quite what I was expecting, I just want to get the content of this undo change at undo and redo (transaction or steps?). my code like:

addCommands() { return { undo: () => ({ state, dispatch }) => { let res = undo(state, (tr) => { let meta = tr.getMeta(“doodle”) console.log(myundo: tr=${tr} meta=${meta}); })

     return res   
     
  },
  redo: () => ({ state, dispatch }) => {
    let res =  redo(state, (tr) => {
      let meta = tr.getMeta("doodle")
      console.log(`myredo: tr=${tr} meta=${meta}`);
    })
    return res
  },
}

}