Skip to content

Commit

Permalink
fix(paste): throw an error when pasting multiple inline boxes into em…
Browse files Browse the repository at this point in the history
…pty block
  • Loading branch information
luolonghao committed May 24, 2024
1 parent abb0d29 commit 12511ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/plugins/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ function pasteFragment(editor: Editor, fragment: DocumentFragment): void {
parts.end.remove();
}
selection.insertFragment(fragment);
editor.renderBoxes();
range.shrinkAfter(lastNode);
}
fixNumberedList(editor.container.children().filter(node => node.isBlock));
Expand Down Expand Up @@ -210,6 +211,5 @@ export default (editor: Editor) => {
editor.event.emit('beforepaste', fragment);
fixClipboardData(fragment);
pasteFragment(editor, fragment);
editor.renderBoxes();
});
};
17 changes: 17 additions & 0 deletions tests/plugins/paste.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,23 @@ describe('plugins / paste', () => {
);
});

it('pastes multiple image boxes into a paragraph', () => {
const content = `
<p><br /><focus /></p>
`;
const output = `
<p><lake-box type="inline" name="image" value="${imageBoxValue}"></lake-box></p>
<p><lake-box type="inline" name="image" value="${imageBoxValue}" focus="end"></lake-box></p>
`;
testPlugin(
content,
output,
editor => {
pasteData(editor, 'text/html', `<p><lake-box type="inline" name="image" value="${imageBoxValue}"></lake-box></p><p><lake-box type="inline" name="image" value="${imageBoxValue}"></lake-box></p>`);
},
);
});

it('pastes image box into an empty paragraph', () => {
const content = `
<p><br /><focus /></p>
Expand Down

0 comments on commit 12511ff

Please sign in to comment.