# Deleting a node in a command

**URL:** <https://discuss.prosemirror.net/t/deleting-a-node-in-a-command/8854>\
**Category:** Uncategorized\
**Created:** [November 17, 2025, 5:13pm UTC](https://discuss.prosemirror.net/t/deleting-a-node-in-a-command/8854 "2025-11-17T17:13:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bencahan](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/bencahan/32/4692_2.png) [@bencahan](https://discuss.prosemirror.net/u/bencahan)\
**Post date:** [November 17, 2025, 5:13pm UTC](https://discuss.prosemirror.net/t/deleting-a-node-in-a-command/8854/1 "2025-11-17T17:13:57Z")

</div>

I have a simple situation where on certain keys I want to remove a paragraph entirely. So, in my command code I have the following:

tr.delete(nodeStart, nodeStart + theNode.nodeSize); dispatch(tr)

The problem is that as I have different types of paragraphs (one spec with a type parameter that changes margins depending on what that type is), the following paragraph is becoming the type of the one I deleted. The node I want gone is being deleted, but as I said, the one being thus moved up is taking on the type of the one I zapped. And so it’s toDOM puts the wrong class and the margins are not right.

I must be missing something simple, like a keep parameter or something, that makes the succeeding node stay as it is, with it’s existing attributes.

---

<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:** [November 17, 2025, 5:31pm UTC](https://discuss.prosemirror.net/t/deleting-a-node-in-a-command/8854/2 "2025-11-17T17:31:13Z")

</div>

This sounds like `nodeStart` is the position at the start of the node, rather than the position before it. Thus, you’re deleting from the start of the node to the start of the node after it (or whatever happens to be one token after the end of the node).

---

<div class="post-metadata">

**Author:** ![bencahan](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/bencahan/32/4692_2.png) [@bencahan](https://discuss.prosemirror.net/u/bencahan)\
**Post date:** [November 17, 2025, 5:33pm UTC](https://discuss.prosemirror.net/t/deleting-a-node-in-a-command/8854/3 "2025-11-17T17:33:16Z")

</div>

**Thanks once again, marjin** , the code that seems to work is:

tr.delete(nodeStart-1, nodeStart + theNode.nodeSize);

---

<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:** [November 17, 2025, 5:48pm UTC](https://discuss.prosemirror.net/t/deleting-a-node-in-a-command/8854/4 "2025-11-17T17:48:09Z")

</div>

You will also need to subtract one from the end of the range. Or, much better, get the actual position before the node (via `ResolvedPos.before` if this comes from a resolved position) and calculate with that.
