Skip to content

pasteHandler doesn't work correctly for list items when their content is empty prior to pasting text. #2330

@spe987-create

Description

@spe987-create

Problem:

  1. Create bullet/numbered/checklist item
  2. Try to paste text into its content
  3. List item gets replaced with paragraph (This happens when list item content is empty).

The following code solves the problem, but I don't if it is ideal:

pasteHandler: ({ event, editor, defaultPasteHandler }) => {
	const currentBlock = editor.getTextCursorPosition().block;
	const blockSpec = editor.schema.blockSchema[currentBlock.type];
	
	const hasInlineContent = blockSpec?.content === "inline";
	const isEmpty = !currentBlock.content || 
		(Array.isArray(currentBlock.content) && currentBlock.content.length === 0);
	
	if (hasInlineContent && isEmpty) {
		const plainText = event.clipboardData?.getData("text/plain");
		if (plainText) {
			editor.pasteText(plainText);
			return true;
		}
	}
	
	return defaultPasteHandler();
},
Screen.Recording.2026-01-04.at.08.54.07.mov

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions