# Revert the delete of a ReplaceStep

**URL:** https://discuss.prosemirror.net/t/revert-the-delete-of-a-replacestep/4150
**Category:** Uncategorized
**Created:** [October 27, 2021, 3:11pm UTC](https://discuss.prosemirror.net/t/revert-the-delete-of-a-replacestep/4150 "2021-10-27T15:11:54Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![SamDuvall](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/samduvall/32/2253_2.png) [@SamDuvall](https://discuss.prosemirror.net/u/SamDuvall)
#### Post date: [October 27, 2021, 3:11pm UTC](https://discuss.prosemirror.net/t/revert-the-delete-of-a-replacestep/4150/1 "2021-10-27T15:11:54Z")

</div>

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.

```auto
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)
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)
#### Post date: [October 27, 2021, 4:56pm UTC](https://discuss.prosemirror.net/t/revert-the-delete-of-a-replacestep/4150/2 "2021-10-27T16:56:46Z")

</div>

You could call [`replaceStep`](https://prosemirror.net/docs/ref/#transform.replaceStep) with the step’s `from` position and slice to try to create a new valid step.
