Finding out what changed in a transaction

I could need some help with an issue I’m dealing with for quite some time now, but cannot find a proper solution for.

I have a tree-like note-structure, where every note has a title and content and can have child-notes again. Yet in the editor, the tree of independently saved notes should appear as if it was a single coherent editor, not a separate one for each note.

Currently, to detect which notes have changed in order to then update the note-hierarchy in the backend, I process each transaction in the dispatchTransaction handler by iterating over the steps of the transaction and locating the note they are in (with the transaction being discarded in case it cannot be processed). This works fine for some cases, but can be really complex for others (like ReplaceAroundSteps spanning several notes). Also, to be able to process the steps, I am currently accessing the to, from and slice of ReplaceStep, which actually aren’t exposed (so I guess I’m not supposed to use them(?)).

Is there a (better) way to do the task I’m trying to accomplish? Should I take a completely different approach for detecting what changed? Help is highly appreciated :slight_smile:

Here is the relevant part of my current schema:

const MIN_NOTE_DEPTH = 0;

const doc = <NodeSpec>{
  content: 'note+'
};

const note = <NodeSpec>{
  content: 'title content childNotes',
  attrs: {noteId: {default: 0}, noteLevel: {default: MIN_NOTE_DEPTH}},
  toDOM(node) {
    return ['note', {class: 'exp-editor__note exp-editor__level-' + node.attrs.noteLevel}, 0];
  }
};

const title = <NodeSpec>{
  content: 'text*',
  marks: '',
  toDOM(node) {
    return ['noteTitle', {class: 'exp-editor__title'}, 0];
  }
};

const content = <NodeSpec>{
  content: '(paragraph | blockquote)+',
  marks: '_',
  toDOM(node) {
    return ['noteContent', {class: 'exp-editor__content'}, 0];
  }
};

const childNotes = <NodeSpec>{
  content: 'note*',
  toDOM(node) {
    return ['childNotes', {class: 'exp-editor__child-notes'}, 0];
  }
};

It is probably preferable to iterate over the mapping of each step (step.getMap().forEach), and map those to the current document through any subsequent steps. You could then either just keep a minimum/maximum changed position, or track and merge individual ranges. And then finally iterate over the change range/ranges and send updates.