fix pasting text (#871)

* fix onPast bug in editor

the event was prevented, if event.clipboardData.files was defined. This always the case. Now we check if this filelist object has at least on entry to start the onPaste handler for file uploads.

Signed-off-by: Philip Molares <philip.molares@udo.edu>

* added e2e test that verifies that pasting text still works

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2020-12-21 11:58:43 +01:00 committed by GitHub
parent e664881f33
commit 1b563f7f89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -95,4 +95,16 @@ describe('Upload', () => {
cy.get('.CodeMirror-activeline > .CodeMirror-line > span')
.should('have.text', 'not empty')
})
it('text paste still works', () => {
const testText = 'a long test text'
const pasteEvent = {
clipboardData: {
getData: (type = 'text') => testText
}
}
cy.get('.CodeMirror-scroll').trigger('paste', pasteEvent)
cy.get('.CodeMirror-activeline > .CodeMirror-line > span')
.should('have.text', `${testText}`)
})
})

View file

@ -70,7 +70,7 @@ interface PasteEvent {
}
const onPaste = (pasteEditor: Editor, event: PasteEvent) => {
if (event && event.clipboardData && event.clipboardData.files) {
if (event && event.clipboardData && event.clipboardData.files && event.clipboardData.files.length > 0) {
event.preventDefault()
const files: FileList = event.clipboardData.files
if (files && files.length >= 1) {