I hope there can be a callback when a certain type of node is removed/added into a doc

I hope there can be a callback when a certain type of node is removed/added into a doc

Right now, I can do this using the

  1. dispatchTransaction callback, but for adding, I need to scan all the steps’ fragments to find out the node types. For deleting, I will see no fragments, then I will have to scan the document to discover the removed nodes.

  2. use a customized node view, since a nodeview has a constructor and a destroy function. But I have to implement the content-updating behavior myself.

I think adding this callback is useful when we want to count or manage nodes globally. Two usecases I have in mind:

  1. auto label equaitions/pics with a number and update them automatically as new equations and images are inserted. We can also refer to them in text using Fig 2. or Eq 3. The references can be updated automatically also.

  1. an automatic content table. As I create new heading blocks, I also generate a small content table for quick navigation.

This is something you’ll have to do yourself based on the information in the transaction. The way the editor works it just sees a new document, and there’s no concept of individual nodes being added or removed.

I believe I can chip in. I had a similar requirement recently, but dropped it due to some other factors.

I found this:

This basically can give you all the nodes that changed during the transaction. The trick is to identify what you need.

For example: if you change a text in a paragraph, that paragraph will be detected as changed, but so will all his parents. This will require some tweaking.

Hope it helps!