# Backspace inside empty paragraph creates a new list node

**URL:** <https://discuss.prosemirror.net/t/backspace-inside-empty-paragraph-creates-a-new-list-node/3784>\
**Category:** Uncategorized\
**Created:** [May 20, 2021, 7:49am UTC](https://discuss.prosemirror.net/t/backspace-inside-empty-paragraph-creates-a-new-list-node/3784 "2021-05-20T07:49:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sie](https://discuss.prosemirror.net/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@sie](https://discuss.prosemirror.net/u/sie)\
**Post date:** [May 20, 2021, 7:49am UTC](https://discuss.prosemirror.net/t/backspace-inside-empty-paragraph-creates-a-new-list-node/3784/1 "2021-05-20T07:49:04Z")

</div>

Hi!

I experienced the problem when pressing the Backspace in an empty paragraph creates a new list node. This behaviour was explained [here](https://discuss.prosemirror.net/t/why-does-joinbackward-behave-differently-with-list-nodes/2854). Does anyone figure out how to fix it? Now, I am trying to handle the Backspace press and rewrite the joinBackward command. Is it a right direction or there is a more proper way to fix it?

Thanks in advance for any help )

---

<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:** [May 20, 2021, 8:26am UTC](https://discuss.prosemirror.net/t/backspace-inside-empty-paragraph-creates-a-new-list-node/3784/2 "2021-05-20T08:26:26Z")

</div>

I assume you are talking about a situation where you have a structure like `<li><p>a</p><p>[cursor]</p></li>`, and press enter there? There’s no need to ‘fix’ this, since it’s intentional behavior. If you don’t want it, don’t bind [`splitListItem`](https://prosemirror.net/docs/ref/#schema-list.splitListItem) to backspace.

---

<div class="post-metadata">

**Author:** ![sie](https://discuss.prosemirror.net/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@sie](https://discuss.prosemirror.net/u/sie)\
**Post date:** [May 20, 2021, 8:36am UTC](https://discuss.prosemirror.net/t/backspace-inside-empty-paragraph-creates-a-new-list-node/3784/3 "2021-05-20T08:36:16Z")

</div>

I’m talking about the case when I have an empty paragraph just below the list. Then, I press the Backspace and I expect that the cursor will get at the end of the last list item (after ‘text’) but instead a new empty list item is created. Like in the example below.

![](https://discuss.prosemirror.net/uploads/secondsite/original/2X/4/4bb1e32b17fce2b20d536cc0e90d8b90e42e01fd.gif)

---

<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:** [May 20, 2021, 8:52am UTC](https://discuss.prosemirror.net/t/backspace-inside-empty-paragraph-creates-a-new-list-node/3784/4 "2021-05-20T08:52:53Z")

</div>

Ah, that’s done by `joinBackward`. It’ll move the current paragraph into the node above it, possibly adding wrapper nodes when necessary. You could add a custom binding to spot this situation and delete the range between the end of the paragraph in the list item and the cursor, if you want to change it.

---

<div class="post-metadata">

**Author:** ![Pier](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/pier/32/616_2.png) [@Pier](https://discuss.prosemirror.net/u/Pier)\
**Post date:** [May 20, 2021, 4:45pm UTC](https://discuss.prosemirror.net/t/backspace-inside-empty-paragraph-creates-a-new-list-node/3784/5 "2021-05-20T16:45:00Z")

</div>

Hi @sie

Out of the box, the `prosemirror-schema-list` package solves a lot of stuff, but we found that many default behaviors didn’t match our expectations of how a rich text editor should work.

For example, when pressing backspace on a node after a list, PM will create a new list node instead of moving the cursor to the end of the last list node. Or when deleting a list node, PM will have 2 paragraphs inside the list item because it always expects list items to have a `<p>` inside.

Like Marijn suggested, a solution is creating custom commands to enhance the default functionality. For example, create a command that will “join” adjacent `<p>` inside list items, and trigger it whenever you press backspace.

---

<div class="post-metadata">

**Author:** ![kepta](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/kepta/32/1674_2.png) [@kepta](https://discuss.prosemirror.net/u/kepta)\
**Post date:** [May 21, 2021, 5:04am UTC](https://discuss.prosemirror.net/t/backspace-inside-empty-paragraph-creates-a-new-list-node/3784/6 "2021-05-21T05:04:47Z")

</div>

> [@sie](#):
>
> Does anyone figure out how to fix it?

Hey sie I implemented this functionality in [https://bangle.dev](https://bangle.dev) which is partly inspired by [atlassians atlaskit](https://atlaskit.atlassian.com/packages/editor/editor-core). You can see the src code of the command [here](https://github.com/kepta/bangle-play/blob/900b1513222326214de09035387f43e0b0f92d50/core/components/list-item/commands.js#L601).

The idea can be summarized into this:

1. Check if the selection is at start of a paragraph
2. Check if you can join to previous list
3. If the above true, try joining it with the list above, [src code](https://github.com/kepta/bangle-play/blob/900b1513222326214de09035387f43e0b0f92d50/core/components/list-item/commands.js#L739) for the command that joins.

---

<div class="post-metadata">

**Author:** ![sie](https://discuss.prosemirror.net/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@sie](https://discuss.prosemirror.net/u/sie)\
**Post date:** [May 21, 2021, 7:12am UTC](https://discuss.prosemirror.net/t/backspace-inside-empty-paragraph-creates-a-new-list-node/3784/7 "2021-05-21T07:12:55Z")

</div>

thank you very much )

---

<div class="post-metadata">

**Author:** ![sie](https://discuss.prosemirror.net/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@sie](https://discuss.prosemirror.net/u/sie)\
**Post date:** [May 21, 2021, 7:13am UTC](https://discuss.prosemirror.net/t/backspace-inside-empty-paragraph-creates-a-new-list-node/3784/8 "2021-05-21T07:13:10Z")

</div>

thanks! it was really helpful )
