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

Pasting list-like content to rich text fields may result in content loss #9151

Open
saevarom opened this issue Sep 6, 2022 · 5 comments
Open

Comments

@saevarom
Copy link
Contributor

saevarom commented Sep 6, 2022

Issue Summary

When pasting "list-like" content into a rich text field with other "list-like" content, the editor will try to convert all "list-like" content sections to lists, and then forget about them. It's hard to explain, but I've included a video of what happens:

Bug description on Youtube

Steps to Reproduce

  1. Open up the bakerydemo. I used the gitpod workspace (https://gitpod.io/#https://github.com/wagtail/bakerydemo/)
  2. Edit the home page
  3. Create a new paragraph block and type in two numbered sections, pressing the Enter key twice between them:

Screenshot 2022-09-06 at 12 36 16

4. Create a line below the first section containing:
a. paragraph 1

It should look like this:
Screenshot 2022-09-06 at 12 45 55

  1. Now paste the following content below the first section:
a. paragraph 1
  1. Save the page.
  2. Edit the page again to see that one of the lists has disappeared. See:

Screenshot 2022-09-06 at 12 47 39

Any other relevant information. For example, why do you consider this a bug and what did you expect to happen instead?

  • I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: (yes)

Technical details

  • Python version: 3.8.12
  • Django version: 4.0.7
  • Wagtail version: 4.0.1 and 2.16.2
  • Browser version: Chrome 104
@saevarom saevarom added status:Unconfirmed Issue, usually a bug, that has not yet been validated as a confirmed problem. type:Bug labels Sep 6, 2022
@thibaudcolas thibaudcolas added component:Rich text and removed status:Unconfirmed Issue, usually a bug, that has not yet been validated as a confirmed problem. labels Sep 9, 2022
@thibaudcolas thibaudcolas self-assigned this Sep 9, 2022
@thibaudcolas
Copy link
Member

Thank you @saevarom! I believe this is a combination of three different issues:

  1. The copy-paste processing unexpectedly treats a. paragraph 1 as a nested ordered list item, even when it’s pasted without nesting
  2. The auto-list-Markdown-ish keyboard shortcuts do not treat a. as a list prefix, so you can type as normal text and then surprisingly it gets converted to a list on paste
  3. The editor ContentState -> Wagtail HTML conversion discards nested list items that aren’t preceded with a non-nested list items (as the editor currently doesn’t allow skipping list levels)

I think all 3 points were conscious design choices on my part, which seemed to make sense in isolation, but taken all together this clearly isn’t up to scratch. I’ll probably have to make changes for all three points, though the content loss is by far the most problematic.

@fyunusa
Copy link
Contributor

fyunusa commented Oct 15, 2022

Screenshot 2022-10-15 at 1 48 04 AM

Hi @thibaudcolas i'm currently looking up on this, i've been able to reproduce the error on a new site which i setup. Trying to look more on the rich text system, to see possible solutions i'll propose.

@thibaudcolas
Copy link
Member

@fyunusa here is the code for the first issue:

https://github.com/thibaudcolas/draftjs-filters/blob/eb5abe2a51f18b37bb3da0771f8fdd7a7d406ae0/src/lib/filters/editor.ts#L75-L81

Second issue: https://github.com/springload/draftail/blob/988c809fb828e3d583932255df845e3dd08cac4f/src/api/constants.ts#L163-L165

Third issue: https://github.com/springload/draftjs_exporter/blob/ee13fa72813a3e079dc4c4305f5aaeadacfd0450/draftjs_exporter/html.py#L69-L79

As you can see this is across three different projects, all of which are used in Wagtail, but definitely standalone projects. I wouldn’t recommend working on this, as there’s a lot to it.

If you want to proceed with this – I’d recommend working on the third issue, which is clearly a bug and where there are no downsides to fixing it. The best next step would be to set up https://github.com/springload/draftjs_exporter for local development and then reproduce the issue there.

@fyunusa
Copy link
Contributor

fyunusa commented Oct 16, 2022

ok, thanks @thibaudcolas. I'll stay calm for now

@fyunusa
Copy link
Contributor

fyunusa commented Oct 16, 2022

Will look for other issues to work on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants