From 858cd3a5898eb6fb332508eb25646351362e2eef Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Thu, 7 Dec 2017 21:08:08 +0530 Subject: [PATCH] Improvement in composer HTML pasting --- .../discourse/components/d-editor.js.es6 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6 index add37c5a8c2..656fda33c17 100644 --- a/app/assets/javascripts/discourse/components/d-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/d-editor.js.es6 @@ -623,7 +623,7 @@ export default Ember.Component.extend({ text = text.substring(0, text.length - 1); } - let rows = text.split("\r").join("").split("\n"); + let rows = text.split("\n"); if (rows.length > 1) { const columns = rows.map(r => r.split("\t").length); @@ -645,20 +645,21 @@ export default Ember.Component.extend({ } const { clipboard, types } = clipboardData(e); - const placeholder = `${ I18n.t('pasting') }`; let plainText = clipboard.getData("text/plain"); const html = clipboard.getData("text/html"); let handled = false; if (plainText) { - plainText = plainText.trim(); + plainText = plainText.trim().replace(/\r/g,""); const table = this._extractTable(plainText); if (table) { - this._addText(this._getSelected(), table); + this.appEvents.trigger('composer:insert-text', table); handled = true; } } + const placeholder = `${ plainText || I18n.t('pasting') }`; + if (html && !handled) { const self = this; @@ -671,9 +672,8 @@ export default Ember.Component.extend({ }).then(response => { self.appEvents.trigger('composer:replace-text', placeholder, response.markdown); }).catch(error => { - if (plainText) { - self.appEvents.trigger('composer:replace-text', placeholder, plainText); - } else { + if (!plainText) { + self.appEvents.trigger('composer:replace-text', placeholder, ""); popupAjaxError(error); } });