How to get mapping for only some of a Transaction's steps?

Is there a way to use something like tr.mapping.map() but for only some of that transaction’s steps?

I have a position that I reference mid-way through applying transforms like so:

let tr = state.tr.insert( … ) // first insert

let positionICareAbout = … // the position I’ll want to map, relative to tr.doc at this point

tr = state.tr.insert( … ).delete( … ) // more inserting and deleting

let finalPositionICareAbout = tr.mapping.map(positionICareAbout) // doesn’t give result I need

tr.mapping.map(positionICareAbout) doesn’t work here because it’ll map “first insert,” which I don’t want because I’m referencing a document state in which it was already applied. I just want do map against the steps “after” it. What’s the best way to do this?

1 Like

Yes, there is, see Mapping.slice.

1 Like