udecode / plate

A rich-text editor powered by AI
https://platejs.org
Other
12k stars 733 forks source link

Cannot delete list element #2041

Closed O4epegb closed 1 year ago

O4epegb commented 1 year ago

Description

List element is not deletable if it's a first element in the editor

Steps

Reproducible in this example https://platejs.org

1) Delete everything 2) Create list element with autoformat rule * 3) Press backspace to delete it 4) List is deleted, but list elements is still there

Sandbox

https://platejs.org

Expectation

List element is deleted

Environment

    "@udecode/plate": "18.13.0",
    "slate": "0.78.0",
    "slate-history": "0.66.0",
    "slate-hyperscript": "0.77.0",
    "slate-react": "0.79.0",

P-176

Funding

Fund with Polar

O4epegb commented 1 year ago

I found what causes it but I'm not really sure how to better fix it.

So it happens because of reset node plugin, it overrides editor.deleteBackward method and adds some logic there:

https://github.com/udecode/plate/blob/37a3c038a4ac298a12013a9ba46dacfa57415e4f/packages/editor/reset-node/src/createResetNodePlugin.ts#L71-L74

In case of a list this code just unsets list block to paragraph block while leaving list element in place. And because it uses withoutNormalizing normalization does not happen if the plugin comes after list plugin in your plugin list. So one of the fixes is just use reset node plugin before list plugin, but for me it seems wrong that the order matters. Or not?

Other solution would be to add some special logic there to handle lists maybe?

zbeyens commented 1 year ago

I think we can generalize that delete backward at the start of the document should reset any block type into a paragraph, so we need a code that unwraps all blocks above and reset the props. With a query(entry) option to be able to prevent that for strict format like Title.

superBertBerg commented 1 year ago

P-178 is most likely the same bug and fixed with this ticket

zbeyens commented 1 year ago

Tracked in https://github.com/udecode/plate/issues/2025