-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
Quill.js adds a 'copy' event listener on the editor, which calls onCaptureCopy().
quill/packages/quill/src/modules/clipboard.ts
Lines 83 to 85 in ebe16ca
| this.quill.root.addEventListener('copy', (e) => | |
| this.onCaptureCopy(e, false), | |
| ); |
onCaptureCopy() calls e.preventDefault() to handle the copy event by quill:
quill/packages/quill/src/modules/clipboard.ts
Lines 171 to 182 in ebe16ca
| onCaptureCopy(e: ClipboardEvent, isCut = false) { | |
| if (e.defaultPrevented) return; | |
| e.preventDefault(); | |
| const [range] = this.quill.selection.getRange(); | |
| if (range == null) return; | |
| const { html, text } = this.onCopy(range, isCut); | |
| e.clipboardData?.setData('text/plain', text); | |
| e.clipboardData?.setData('text/html', html); | |
| if (isCut) { | |
| deleteRange({ range, quill: this.quill }); | |
| } | |
| } |
But there is a case, where quill.selection.getRange() returns null, and the function returns without copying anything but after it has already called e.preventDefault(), so the browser doesn't copy anything either.
I think e.preventDefault(); should move two lines down, after the if (range == null) return;.
I.e., onCaptureCopy() should preventDefault() only when it handles the copy event itself.
This issue causes an issue in read-only quill viewer where you cannot copy the entire text when you select it via mouse triple-click.
You can observe the issue on the ngx-quill official examples page:
- Go to https://killercodemonkey.github.io/ngx-quill-example/
- Scroll to the View format: object example.
- Triple-click the "Hello World!" text.
- Ctrl+C, Ctrl+V.
- Hello World wasn't copied...

