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

Turning multiple nodes of text into a list doesn't work if schema forces list item content to have a single paragraph #1205

Open
3 tasks done
marko-hologram opened this issue Sep 13, 2021 · 2 comments

Comments

@marko-hologram
Copy link

Issue details

When defining a schema that prevents list nesting by forcing a single paragraph in list item, wrapInList doesn't work anymore when multiple nodes of text are selected.

Steps to reproduce

https://codesandbox.io/s/blue-haze-pbtei?file=/src/index.js

  1. Select multiple lines of text in editor
  2. Notice that "Wrap in bullet list" and "Wrap in ordered list" aren't available

Setting list content to "paragraph*" (zero or more paragraphs) or "paragraph+" (one or more paragraphs) instead of "paragraph" (one paragraph) will make this work.

ProseMirror version

prosemirror-example-setup - 1.1.2
prosemirror-model - 1.14.3
prosemirror-schema-basic - 1.1.2
prosemirror-schema-list - 1.1.5
prosemirror-state - 1.3.4
prosemirror-view - 1.20.1

Affected platforms

All tested on Windows 10 21H1:

  • Chrome 93.0.4577.63
  • Firefox 93
  • Internet Explorer 11

Screenshots / Screencast (Optional)

WpZsBDKftI.mp4

Expected behavior

Maybe I don't know ProseMirror too well, but I would expect that multiple lines of text could be wrapped into a list if list item content is forced to have a single paragraph.

Additional info

I did poke around a bit and found that findWrapping() inside wrapInList() returns null. Don't have more findings about this since I'm not 100% sure what's going on.

P.S. Thanks for all your amazing work!

@marijnh
Copy link
Member

marijnh commented Sep 13, 2021

The current list-wrapping logic tries to first wrap the entire selected range in a single item and then split it, which indeed doesn't work in this case. That's an unfortunate effect of trying to write ProseMirror commands—they always make some assumption about the schema, and won't automatically work with every possible schema. See also https://discuss.prosemirror.net/t/wrapinlist-does-not-work-with-itemcontent-set-to-paragraph-ordered-list-bullet-list/2602/2

What would work in this case would be to first wrap the first block and then move the items after that into the list one by one. You could try to write a command that works like that, or submit a pull request that updates the implementation in prosemirror-schema-list

@marko-hologram
Copy link
Author

The current list-wrapping logic tries to first wrap the entire selected range in a single item and then split it, which indeed doesn't work in this case. That's an unfortunate effect of trying to write ProseMirror commands—they always make some assumption about the schema, and won't automatically work with every possible schema. See also https://discuss.prosemirror.net/t/wrapinlist-does-not-work-with-itemcontent-set-to-paragraph-ordered-list-bullet-list/2602/2

Thank you for this quick answer. Sorry I opened an issue when there is this forum post, but I didn't manage to find it while searching for similar issues.

What would work in this case would be to first wrap the first block and then move the items after that into the list one by one. You could try to write a command that works like that, or submit a pull request that updates the implementation in prosemirror-schema-list

Thanks for the suggestion, I'll see what I can do. I'll try to go for a PR, but ProseMirror can be intimidating so I'm not sure if I'll be able to tackle it 😄

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

No branches or pull requests

2 participants