Skip to content

Commit adb7bd8

Browse files
committed
Handle paste event
Signed-off-by: Lukas Schaefer <lukas@lschaefer.xyz>
1 parent 7f5aae7 commit adb7bd8

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/components/ChattyLLM/InputArea.vue

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
:maxlength="64_000"
5151
:multiline="isMobile"
5252
dir="auto"
53+
@paste="onPaste"
5354
@update:model-value="$emit('update:chatContent', $event)"
5455
@submit="onSubmitText" />
5556
<div class="input-area__button-box">
@@ -198,6 +199,13 @@ export default {
198199
},
199200
200201
methods: {
202+
onPaste(e) {
203+
if (!this.multimodalChatAvailable || e.clipboardData.files.length === 0) {
204+
return
205+
}
206+
e.preventDefault()
207+
this.uploadFiles(e.clipboardData.files)
208+
},
201209
focus() {
202210
this.$nextTick(() => {
203211
this.$refs.richContenteditable.focus()
@@ -228,12 +236,17 @@ export default {
228236
this.$refs.fileInput.click()
229237
},
230238
onUploadFileSelected() {
231-
const files = this.$refs.fileInput.files
239+
this.uploadFiles(this.$refs.fileInput.files)
240+
.finally(() => {
241+
this.$refs.fileInput.value = ''
242+
})
243+
},
244+
uploadFiles(files) {
232245
if (!files || files.length === 0) {
233-
return
246+
return Promise.resolve()
234247
}
235248
this.isUploading = true
236-
Promise.all(Array.from(files).map(f => uploadInputFile(f)))
249+
return Promise.all(Array.from(files).map(f => uploadInputFile(f)))
237250
.then((responses) => {
238251
const fileIds = responses.map(response => response.data.ocs.data.fileId)
239252
this.attachedFileIds = [...this.attachedFileIds, ...fileIds]
@@ -244,7 +257,6 @@ export default {
244257
})
245258
.finally(() => {
246259
this.isUploading = false
247-
this.$refs.fileInput.value = ''
248260
})
249261
},
250262
async onChooseFromNextcloud() {

0 commit comments

Comments
 (0)