From 1b563f7f891b4d102e3e9e0728b8f3ee4ea87bf9 Mon Sep 17 00:00:00 2001 From: Philip Molares Date: Mon, 21 Dec 2020 11:58:43 +0100 Subject: [PATCH] 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 * added e2e test that verifies that pasting text still works Signed-off-by: Philip Molares --- cypress/integration/upload.spec.ts | 12 ++++++++++++ src/components/editor/editor-pane/editor-pane.tsx | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cypress/integration/upload.spec.ts b/cypress/integration/upload.spec.ts index 40dd70b25..c5d0ccdbc 100644 --- a/cypress/integration/upload.spec.ts +++ b/cypress/integration/upload.spec.ts @@ -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}`) + }) }) diff --git a/src/components/editor/editor-pane/editor-pane.tsx b/src/components/editor/editor-pane/editor-pane.tsx index 65ccf4787..a90e74c76 100644 --- a/src/components/editor/editor-pane/editor-pane.tsx +++ b/src/components/editor/editor-pane/editor-pane.tsx @@ -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) {