Prosemirror-changeset: How to also see the changes in marks and attrs?

I was able to use prosemirror-changeset to compute the differences between two versions of the same document. The problem is that it only shows the differences in the node’s content. If a step changes a node’s marks or a node’s attrs, it does not get reported as a change.

How do I use prosemirror-changeset find changes in marks and attrs? Would I need to modify the code for prosemirror-changeset? What function inside of prosemirror-changeset would I need to modify?

The steps I’m currently taking are:

  1. Start with the JSON of two different versions of the same document.
  2. Create Prosemirror Node objects from the JSON representations
  3. Use a library called modevol-prosemirror-recreate-transform to calculate the transform between the two versions of the same Doc
  4. Get the StepMaps mapping from the transform
  5. Use Changeset.create and Changeset.addSteps to calculate a ChangeSet
1 Like

prosemirror-changeset, being intended for the use case of highlighting inline changed ranges, doesn’t track mark and attribute changes. Your process seems a bit circuitous — recreate-transform will do diffing between two versions to find changed ranges and then create steps for those changes, then prosemirror-changeset will take the ranges from those steps again, and do another diff to minimize them. It sounds like what you’re interested in are the initially determined changed ranges. Maybe you can figure out how prosemirror-changeset initially finds the changed ranges and see if you can use that part directly.

You might be able to use the data field of addSteps to do this? It’s used by sameSpans to determine if two ranges are equal.

Could use that to hopefully extend changeset to account for attr_step and mark_step: prosemirror-transform/src at master · ProseMirror/prosemirror-transform · GitHub

@marjin What I want is to show a side by side view. The left hand side shows the old document, the right hand side shows the new document. Then on each side I want to highlight what has been changed so that the user can quickly see the differences. I want to highlight when blocks have been added or removed or changed. I want to highlight when marks have been added to inline content.

I don’t have any steps or transform from the old document to the new document. So that is why I’m using modevol-prosemirror-recreate-transform to generate a Transform, mapping, and steps.

I need a function that, given a Transform, will return a Changeset that includes all of the changes. But prosemirror-changeset only returns some of the changes that I want. It doesn’t include changes to marks or attrs.

I’m not sure if I know enough about Transform, Step, and StepMap to write that function.

I could try to do it in a single column view. But it was also messy trying to do it that.

The tr from recreateTransform should have the information that tells you what marks or attrs were added or deleted by looking at the steps themselves.

https://prosemirror.net/docs/ref/#transform.AddMarkStep https://prosemirror.net/docs/ref/#transform.RemoveMarkStep https://prosemirror.net/docs/ref/#transform.AddNodeMarkStep https://prosemirror.net/docs/ref/#transform.RemoveNodeMarkStep https://prosemirror.net/docs/ref/#transform.AttrStep https://prosemirror.net/docs/ref/#transform.DocAttrStep