fix: Prevent invalid attachments from blocking text paste (#13135)

This commit is contained in:
Sivin Varghese
2025-12-22 21:17:35 +05:30
committed by GitHub
parent d408f664cb
commit 53c21e6ad3
3 changed files with 28 additions and 18 deletions

View File

@@ -171,10 +171,13 @@ const onPaste = e => {
const files = e.clipboardData?.files; const files = e.clipboardData?.files;
if (!files?.length) return; if (!files?.length) return;
Array.from(files).forEach(file => { // Filter valid files (non-zero size)
const { name, type, size } = file; Array.from(files)
onFileUpload({ file, name, type, size }); .filter(file => file.size > 0)
}); .forEach(file => {
const { name, type, size } = file;
onFileUpload({ file, name, type, size });
});
}; };
useEventListener(document, 'paste', onPaste); useEventListener(document, 'paste', onPaste);

View File

@@ -676,11 +676,18 @@ function createEditorView() {
typingIndicator.stop(); typingIndicator.stop();
emit('blur'); emit('blur');
}, },
paste: (_view, event) => { paste: (view, event) => {
if (props.disabled) return; if (props.disabled) return;
const data = event.clipboardData.files; const { files } = event.clipboardData;
if (data.length > 0) { if (!files.length) return;
event.preventDefault(); event.preventDefault();
// Paste text content alongside files (e.g., spreadsheet data from Numbers app)
// Numbers app includes invalid 0-byte attachments with text, so we paste the text here
// while ReplyBox filters and handles valid file attachments
const text = event.clipboardData.getData('text/plain');
if (text) {
view.dispatch(view.state.tr.insertText(text));
emitOnChange();
} }
}, },
}, },

View File

@@ -692,20 +692,20 @@ export default {
}, },
onPaste(e) { onPaste(e) {
// Don't handle paste if compose new conversation modal is open // Don't handle paste if compose new conversation modal is open
if (this.newConversationModalActive) { if (this.newConversationModalActive) return;
return;
}
const data = e.clipboardData.files; const data = e.clipboardData.files;
if (!this.showRichContentEditor && data.length !== 0) { if (!this.showRichContentEditor && data.length !== 0) {
this.$refs.messageInput?.$el?.blur(); this.$refs.messageInput?.$el?.blur();
} }
if (!data.length || !data[0]) {
return; // Filter valid files (non-zero size)
} Array.from(e.clipboardData.files)
data.forEach(file => { .filter(file => file.size > 0)
const { name, type, size } = file; .forEach(file => {
this.onFileUpload({ name, type, size, file: file }); const { name, type, size } = file;
}); this.onFileUpload({ name, type, size, file });
});
}, },
toggleUserMention(currentMentionState) { toggleUserMention(currentMentionState) {
this.showUserMentions = currentMentionState; this.showUserMentions = currentMentionState;