ianstormtaylor / slate

A completely customizable framework for building rich text editors. (Currently in beta.)
http://slatejs.org
MIT License
29.29k stars 3.21k forks source link

Voids shouldn't be deleted when the node after them is deleted #4896

Open cmmartin opened 2 years ago

cmmartin commented 2 years ago

Description When you have a text node directly after a void node and you select the (empty) text node and press delete, the text node and the void node are both deleted. Only the text node should be deleted and the selection should move to the void node.

Recording slate-bug

Sandbox This can be reproduced in any of the examples that contain a void node. For example, https://www.slatejs.org/examples/images and https://www.slatejs.org/examples/editable-voids

Steps To reproduce the behavior:

  1. Go to https://www.slatejs.org/examples/editable-voids
  2. Move the cursor to the paragraph below either image and delete the text
  3. With the cursor in the empty paragraph, press delete
  4. The paragraph AND the void node (image) above it are both deleted

Expectation Only the selected paragraph should be removed and the selection should move to the void node above it

Environment

Context The main issue here is it means a void node can't be the last node in a document. By deleting the nodes after it, you end up deleting the void node itself

beewolf233 commented 2 years ago

I have this question too

dylans commented 2 years ago

In our app we have a normalization rule to always have an empty zero width text element after the void (and semi-related a block element at the end to make it easier to select around anything).

doougui commented 2 months ago

In our app we have a normalization rule to always have an empty zero width text element after the void (and semi-related a block element at the end to make it easier to select around anything).

@dylans since slate isn't controlled, how did you manage to do that?