diff --git a/ts/quill/signal-clipboard/util.ts b/ts/quill/signal-clipboard/util.ts index 355ecf0c56..c4d2601da4 100644 --- a/ts/quill/signal-clipboard/util.ts +++ b/ts/quill/signal-clipboard/util.ts @@ -9,6 +9,19 @@ export function createEventHandler({ deleteSelection: boolean; }) { return (event: ClipboardEvent): void => { + // If we're attempting to cut, and focus is not in one of our composer elements, we + // let the browser do its default behavior. We don't need formatting from them. + if (deleteSelection) { + const { activeElement } = document; + if ( + !activeElement || + activeElement.matches('input, textarea') || + !activeElement.closest('[contenteditable=true]') + ) { + return; + } + } + if (!event.clipboardData) { return; } @@ -25,9 +38,11 @@ export function createEventHandler({ container.appendChild(range.cloneContents()); } + // We fail over to selection.toString() because we can't pull values from the DOM if + // the selection is within an or