ConverationView.onPaste: Better handling of clipboard contents

This commit is contained in:
Scott Nonnenberg 2023-10-24 10:18:58 -07:00 committed by GitHub
parent 607349e0b8
commit a1e7efee12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 6 deletions

View file

@ -1,7 +1,16 @@
diff --git a/node_modules/quill/dist/quill.js b/node_modules/quill/dist/quill.js diff --git a/node_modules/quill/dist/quill.js b/node_modules/quill/dist/quill.js
index 811b3d0..fe5d034 100644 index 811b3d0..9243ab6 100644
--- a/node_modules/quill/dist/quill.js --- a/node_modules/quill/dist/quill.js
+++ b/node_modules/quill/dist/quill.js +++ b/node_modules/quill/dist/quill.js
@@ -4295,7 +4295,7 @@ var Scroll = function (_Parchment$Scroll) {
value: function enable() {
var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
- this.domNode.setAttribute('contenteditable', enabled);
+ this.domNode.setAttribute('contenteditable', enabled ? 'plaintext-only' : false);
}
}, {
key: 'formatAt',
@@ -8896,7 +8896,8 @@ var debug = (0, _logger2.default)('quill:clipboard'); @@ -8896,7 +8896,8 @@ var debug = (0, _logger2.default)('quill:clipboard');
var DOM_KEY = '__ql-matcher'; var DOM_KEY = '__ql-matcher';

View file

@ -34,6 +34,10 @@ body {
} }
} }
[contenteditable] {
-webkit-user-modify: read-write-plaintext-only;
}
::-webkit-scrollbar { ::-webkit-scrollbar {
// For vertical scrollbars // For vertical scrollbars
width: 9px; width: 9px;

View file

@ -57,14 +57,15 @@ export function ConversationView({
const onPaste = React.useCallback( const onPaste = React.useCallback(
(event: React.ClipboardEvent<HTMLDivElement>) => { (event: React.ClipboardEvent<HTMLDivElement>) => {
event.stopPropagation();
event.preventDefault();
if (!event.clipboardData) { if (!event.clipboardData) {
return; return;
} }
const { items } = event.clipboardData; const { items } = event.clipboardData;
const fileItems = [...items].filter(item => item.kind === 'file'); const fileItems = [...items].filter(item => item.kind === 'file');
if (fileItems.length === 0) {
return;
}
const allVisual = fileItems.every(item => { const allVisual = fileItems.every(item => {
const type = item.type.split('/')[0]; const type = item.type.split('/')[0];
@ -84,6 +85,9 @@ export function ConversationView({
files, files,
}); });
event.stopPropagation();
event.preventDefault();
return; return;
} }
@ -93,6 +97,9 @@ export function ConversationView({
conversationId, conversationId,
files: [firstAttachment], files: [firstAttachment],
}); });
event.stopPropagation();
event.preventDefault();
} }
}, },
[conversationId, processAttachments] [conversationId, processAttachments]

View file

@ -16,7 +16,7 @@ export function createEventHandler({
if ( if (
!activeElement || !activeElement ||
activeElement.matches('input, textarea') || activeElement.matches('input, textarea') ||
!activeElement.closest('[contenteditable=true]') !activeElement.closest('[contenteditable=plaintext-only]')
) { ) {
return; return;
} }

View file

@ -27,7 +27,7 @@ window.addEventListener('contextmenu', e => {
const node = e.target as Element | null; const node = e.target as Element | null;
const isEditable = Boolean( const isEditable = Boolean(
node?.closest('textarea, input, [contenteditable="true"]') node?.closest('textarea, input, [contenteditable="plaintext-only"]')
); );
const isLink = Boolean(node?.closest('a')); const isLink = Boolean(node?.closest('a'));
const isImage = Boolean(node?.closest('.Lightbox img')); const isImage = Boolean(node?.closest('.Lightbox img'));