I have a plugin where I need to inspect what just happened to the document from appendTransaction. E.g. say I want to resolve the from of a replace step in the document. I don’t think I can simply tr.doc.resolve(from) or tr.before.resolve(from), right?
I think I need to:
Build up a combined mapping of all the steps prior to the step in question
Map from through that and resolve with tr.before.resolve(mappedFrom)
Is that right? Any pointers on how to do it? I think I can combine the step-maps using step.map(otherStep.getMap())
Do you need the ranges in the new document, or in the old? You can use tr.mapping.slice to get a partial mapping for a transaction, and use that to map positions from steps (which you get from their step map, not from step.from/step.to) that aren’t the last forward to apply to the transaction’s end document. You can do a similar thing (mapping back through inverted mappings) to get the ranges
Thanks. Right now I need the ranges in the old document. I’m trying to detect if a ReplaceStep exactly replaces a node of a certain type. But it’s useful to know how this works both ways.
Could you elaborate a bit on why step.from/step.to are not suitable? It seems a lot simpler to use those than the step map.
And to clarify, when you say to get the positions from the step map, I think you mean to call step.getMap().forEach(...) right?