Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select all content and paste the content copied from other editors. The block node cannot be deleted. #5630

Open
natamox opened this issue Apr 6, 2024 · 0 comments
Labels

Comments

@natamox
Copy link

natamox commented Apr 6, 2024

Description
Prerequisite: the last content is an image (or other block element)
There are two situations:

  1. There is only an empty paragraph after the picture.
  2. Two empty paragraph.

Recording

  1. One empty paragraph
    https://github.com/ianstormtaylor/slate/assets/120485290/f2be67c6-1277-4222-8af8-9a92aad7ee70
  2. Two empty paragraph
    https://github.com/ianstormtaylor/slate/assets/120485290/f75067d0-562a-4e41-a08c-13b745f99022

Steps
After carefully studying and tracing the code, I found that the problem occurred in the insertFragment function.

The first case:

at = Editor.unhangRange(editor, at, { voids })

It seems that the Editor.unhangRange method returns a path that does not include the image. So when Transforms.delete was deleted, it was not deleted.
image

The second case:
The "at" path returned seems to be correct, and through the debugging panel on the right, you can see that the text of the first element in editor.children is empty, indicating that Transforms.delete has worked, but the image element is still there.

Transforms.delete(editor, { at })

image

Then look at it with the right example
Below the image followed by a paragraph with text, you can see that it works as expected
image

Summarize

So in the end, I concluded that the first one is Editor.unhangRange which seems to have some problems, because in the first case it returns a Path that does not meet the expectations. But I'm not sure why this is happening. I also studied the source code of unhangRange and found that this may be the problem. It only matches text. But I don’t fully understand what this intention is, so I don’t dare to modify the source code easily.

for (const [node, path] of Editor.nodes(editor, {
at: before,
match: Text.isText,
reverse: true,
voids,
})) {

The second one is that I suspect that Transforms.delete also has some problems, because judging from the second example, it returns the correct Path, but it is not exactly as expected. The only difference between it and the normal situation is the offest in Path

I tried to solve these problems, but found some difficulties because I didn't fully understand the specific logic of these functions. So if anyone has any ideas I would be grateful, thank you 🙏

@natamox natamox added the bug label Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant