You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copying and pasting a list item wrapped in a ul results in a list item wrapped in a ol surrounded by two empty paragraphs instead of resulting in the copied content.
I can explain this issue. When the listItem node is been selected (e.g. a NodeSelection), ProseMirror will only write <li> ... </li> into the clipboard when coping, so it loses the context about the outer node (orderedList or bulletList).
Here is the data ProseMirror write into clipboard:
I found a way to customize the default behavior and solve the issue by using a custom transformCopied function:
functiontransformCopied(slice,view){// If a single list item node is copied, we want to wrap it in its parent so that// pasting the slice results in the correct list type (e.g. ordered vs unordered list)if(slice.openStart==0&&slice.openEnd==0&&slice.content.childCount==1){constcopiedNode=slice.content.firstChildif(copiedNode.type.spec.isListItem){// Search for the parent of the copied list itemletcopiedNodeParentview.state.doc.descendants((node,pos,parent)=>{if(copiedNodeParent)returnfalseif(node==copiedNode){copiedNodeParent=parentreturnfalse}})// Create a new Slice that includes the parent of the list itemif(copiedNodeParent)returnnewSlice(Fragment.from(copiedNodeParent.type.create(null,slice.content)),1,1)}}returnslice}
Depending on the schema used for the list item, copiedNode.type.spec.isListItem needs to be adjusted (e.g. copiedNode.type.name == 'list_item'). In case the attributes of the parent list should be kept as part of the copy, one can use copiedNodeParent.copy(slice.content) instead of copiedNodeParent.type.create(null, slice.content).
I'm not sure if this is the best or recommended way to achieve this, but it solves the issue for me.
Issue details
Copying and pasting a list item wrapped in a
ul
results in a list item wrapped in aol
surrounded by two empty paragraphs instead of resulting in the copied content.Steps to reproduce
Ctrl+X
to cut the selectionCtrl+V
to paste the contentProseMirror version
prosemirror-view 1.6.8
prosemirror-model 1.6.4
Affected platforms
Screenshots / Screencast (Optional)
Before cut


After paste
The text was updated successfully, but these errors were encountered: