diff --git a/src/rich_text_editor/model/RichTextEditor.js b/src/rich_text_editor/model/RichTextEditor.js index bd15bbe1b..ea2031e51 100644 --- a/src/rich_text_editor/model/RichTextEditor.js +++ b/src/rich_text_editor/model/RichTextEditor.js @@ -92,6 +92,7 @@ export default class RichTextEditor { this.setEl(el); this.updateActiveActions = this.updateActiveActions.bind(this); this.__onKeydown = this.__onKeydown.bind(this); + this.__onPaste = this.__onPaste.bind(this); const acts = (settings.actions || []).map(action => { let result = action; @@ -201,6 +202,7 @@ export default class RichTextEditor { el.contentEditable = !!enable; method(el, 'mouseup keyup', this.updateActiveActions); method(doc, 'keydown', this.__onKeydown); + method(doc, 'paste', this.__onPaste); this.enabled = enable; if (enable) { @@ -237,6 +239,18 @@ export default class RichTextEditor { } } + __onPaste(ev) { + const clipboardData = ev.clipboardData || window.clipboardData; + const text = clipboardData.getData('text'); + const textHtml = clipboardData.getData('text/html'); + // Replace \n with
in case of plain text + if (text && !textHtml) { + ev.preventDefault(); + const html = text.replace(/(?:\r\n|\r|\n)/g, '
'); + this.doc.execCommand('insertHTML', false, html); + } + } + /** * Sync actions with the current RTE */