Revert the delete of a ReplaceStep

Is there a technique to revert the deleted portion of a ReplaceStep and only leave the inserted slice? The following works fine when deleting text, but runs into trouble on node boundaries (e.g. paragraphs, list items). I suspect it has something to do with joining / depths, but I am unsure if there is anything I can do about it.

const applyStep = ({
  state,
  step,
  tr
}: {
  state: EditorState
  step: Step
  tr: Transform
}) => {
  tr.step(step)

  if (step instanceof ReplaceStep) { 
    if (step.from !== step.to) {
      const invertedStep = step.invert(state.doc) as ReplaceStep
      const deletedStep = new ReplaceStep(
        invertedStep.from,
        invertedStep.from,
        invertedStep.slice,
        invertedStep.structure
      )
      tr.step(deletedStep)
    }
  }
}

You could call replaceStep with the step’s from position and slice to try to create a new valid step.