Allow to pass optional attributes to splitListItem #11
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "patch-1"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi,
When splitting a list item to create a new one, we may want the new item to have specific attributes. My use case is splitting items for a task list: if you split a checked item, you may want the new item to be unchecked. But as a default, the splitted node is copied with the same attribute, here
checked: true.Problem: somehow with the proposed code,
canSplitItemis false. Yet if I uncomment this check, the splitting works well. I haven't yet figured the change needed incanSplitItem.I haven't fully investigated but I suspect that in "prosemirror-transform/src/structure.ts" this check doesn't pass if I specify some attributes:
Looks good. Merged.
@marijnh thanks but did you take a look at the "canSplit" issue? It's somehow never true when I pass an attribute, despite the split working correctly when I comment the "canSplit" call, so passing an attribute will have no effect
Oh, I missed that. (Next time, please mark the PR as a draft if it's not ready to be merged.)
I can't reproduce the issue. Can you provide the schema you're using?
Yes sorry for the messy PR!
The relevant part of the schema is like so (nothing fancy for lists):
So the problem is that
canSplit(tr.doc, $from.pos, 2, types)):types === [{type: schema.nodes.list_item, attrs: {}} /* this prevents copying the item attributes*/, {type: nextType }types === [null /* this will copy the item attributes*/, { type: nextType}]Also I've tried crafting a unit test like so:
But it doesn't seem to actually check for attributes so it's not reliable
Thanks, that helps. That was a bug in
canSplit— prosemirror-transform 1.7.3 should fix it.