feat: Adds support for paste attachment with keys. (#3293)

* copy paste files

* Minor fixes

* Adds support for pasting attachment

* Minor files

* Review fixes
This commit is contained in:
Sivin Varghese 2021-11-02 10:05:49 +05:30 committed by GitHub
parent 0651b11fda
commit 03b1a3d045
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -52,7 +52,7 @@
@toggle-canned-menu="toggleCannedMenu"
/>
</div>
<div v-if="hasAttachments" class="attachment-preview-box">
<div v-if="hasAttachments" class="attachment-preview-box" @paste="onPaste">
<attachment-preview
:attachments="attachedFiles"
:remove-attachment="removeAttachment"
@ -314,11 +314,22 @@ export default {
// Donot use the keyboard listener mixin here as the events here are supposed to be
// working even if input/textarea is focussed.
document.addEventListener('keydown', this.handleKeyEvents);
document.addEventListener('paste', this.onPaste);
},
destroyed() {
document.removeEventListener('keydown', this.handleKeyEvents);
document.removeEventListener('paste', this.onPaste);
},
methods: {
onPaste(e) {
const data = e.clipboardData.files;
if (!data.length || !data[0]) {
return;
}
const file = data[0];
const { name, type, size } = file;
this.onFileUpload({ name, type, size, file });
},
toggleUserMention(currentMentionState) {
this.hasUserMention = currentMentionState;
},