From adc8513f4174fa4ef6a3a9b98dc28a7794db7a7d Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 6 Jun 2023 12:06:58 -0700 Subject: [PATCH] Implement cut/copy correctly for input/textarea elements --- ts/quill/signal-clipboard/util.ts | 17 ++++++++++++++++- ts/util/lint/exceptions.json | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) 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