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

Cannot copy or delete whole list #3469

Open
thallada opened this issue Jan 27, 2020 · 4 comments
Open

Cannot copy or delete whole list #3469

thallada opened this issue Jan 27, 2020 · 4 comments
Labels

Comments

@thallada
Copy link
Contributor

Do you want to request a feature or report a bug?

A bug

What's the current behavior?

I can reproduce this in the examples: https://www.slatejs.org/examples/richtext

With this list as the only content in the editor:

Screen Shot 2020-01-27 at 2 39 00 PM

Cmd+A to select all appears to select the whole list:

Screen Shot 2020-01-27 at 2 39 47 PM

But, if I copy it, only the <li> elements are in the html clipboard content, and not the containing <ol>. This is what happens when I paste into a Google doc:

Screen Shot 2020-01-27 at 2 46 43 PM

Also If I try to delete, only the list items are deleted, but the list itself stays:

Screen Shot 2020-01-27 at 2 41 13 PM

If there is some other content in the editor, like an empty paragraph above the list, then copying works (includes the whole <ol> and child <li>s).

Screen Shot 2020-01-27 at 2 43 46 PM

Pasted content:
Screen Shot 2020-01-27 at 2 47 14 PM

However, if I backspace to delete, this happens...

Screen Shot 2020-01-27 at 2 44 31 PM

Note that the bullet lacks indentation and the unordered list toolbar button is not bolded. I inspected the DOM and it looks like there is an <li> without a containing <ol> or <ul>. There's no way to delete it.

Slate: 0.57.1
Browser: Chrome
OS: Mac

What's the expected behavior?

I expected that:

  1. When I select all and delete there is no content left in the editor.
    • To be fair, when I tried this in https://draftjs.org/ I noticed that they also leave behind the first bullet of the list after deleting.
  2. When I select all and copy, the copied contents contain the wrapping <ol> or <ul>.
  3. When I select all and delete when there is a list and an empty paragraph, there is no content left in the editor.
@thallada
Copy link
Contributor Author

I was able to fix the 3rd issue (the <li> left behind after select all and deleting a paragraph and list) with this plugin:

const withNoListlessListItems = editor => {
  editor.deleteFragment = (...args) => {
    deleteFragment(...args)

    const listItems = Editor.nodes(editor, {
      match: n => n.type === "list-item",
    })

    for (const listItem of listItems) {
      const parent = Editor.parent(editor, listItem[1])
      if (parent && !["ordered-list", "unordered-list"].includes(parent[0].type)) {
        Transforms.setNodes(
          editor,
          { type: "paragraph" },
          {
            at: listItem[1],
            match: n => n.type === "list-item",
          }
        )
      }
    }
  }

  return editor
}

It looks for list-items which do not have a ordered-list or unordered-list parent after deleteFragment runs and sets them to a paragraph.

@thesunny thesunny added the bug label Mar 7, 2020
@Sinled
Copy link

Sinled commented Aug 20, 2020

any updates or workarounds for this issue?

@kunkunL
Copy link

kunkunL commented Nov 20, 2020

is there any progress on this question,please

@almatyssias
Copy link

I've noticed this seems to be an issue for all block level nodes. I've encountered the same issue with headers tags, etc.
The issue seems to be the selection is being set just inside the block node but not including the block node itself.

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

5 participants