diff --git a/CHANGELOG.md b/CHANGELOG.md index 21315b3dd7..2b321c7c79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Fix `Quill#getSemanticHTML()` for list items - Remove unnecessary Firefox workaround +- **Clipboard** Fix redundant newlines when pasting from external sources # 2.0.0-rc.2 diff --git a/packages/quill/src/modules/clipboard.ts b/packages/quill/src/modules/clipboard.ts index ead9758d29..df1c0c250d 100644 --- a/packages/quill/src/modules/clipboard.ts +++ b/packages/quill/src/modules/clipboard.ts @@ -529,7 +529,10 @@ function matchList(node: Node, delta: Delta, scroll: ScrollBlot) { function matchNewline(node: Node, delta: Delta, scroll: ScrollBlot) { if (!deltaEndsWith(delta, '\n')) { - if (isLine(node, scroll)) { + if ( + isLine(node, scroll) && + (node.childNodes.length > 0 || node instanceof HTMLParagraphElement) + ) { return delta.insert('\n'); } if (delta.length() > 0 && node.nextSibling) { diff --git a/packages/quill/test/unit/modules/clipboard.spec.ts b/packages/quill/test/unit/modules/clipboard.spec.ts index a7e929dd44..eaa98a169d 100644 --- a/packages/quill/test/unit/modules/clipboard.spec.ts +++ b/packages/quill/test/unit/modules/clipboard.spec.ts @@ -563,5 +563,11 @@ describe('Clipboard', () => { .insert('\n'), ); }); + + test('ignore empty elements except paragraphs', () => { + const html = '
hello
my

world
'; + const delta = createClipboard().convert({ html }); + expect(delta).toEqual(new Delta().insert('hello\nmy\n\nworld')); + }); }); });