Improvement in composer HTML pasting

This commit is contained in:
Vinoth Kannan 2017-12-07 21:13:09 +05:30
commit 5cceb95f92
1 changed files with 7 additions and 7 deletions

View File

@ -623,7 +623,7 @@ export default Ember.Component.extend({
text = text.substring(0, text.length - 1); text = text.substring(0, text.length - 1);
} }
let rows = text.split("\r").join("").split("\n"); let rows = text.split("\n");
if (rows.length > 1) { if (rows.length > 1) {
const columns = rows.map(r => r.split("\t").length); const columns = rows.map(r => r.split("\t").length);
@ -645,20 +645,21 @@ export default Ember.Component.extend({
} }
const { clipboard, types } = clipboardData(e); const { clipboard, types } = clipboardData(e);
const placeholder = `${ I18n.t('pasting') }`;
let plainText = clipboard.getData("text/plain"); let plainText = clipboard.getData("text/plain");
const html = clipboard.getData("text/html"); const html = clipboard.getData("text/html");
let handled = false; let handled = false;
if (plainText) { if (plainText) {
plainText = plainText.trim(); plainText = plainText.trim().replace(/\r/g,"");
const table = this._extractTable(plainText); const table = this._extractTable(plainText);
if (table) { if (table) {
this._addText(this._getSelected(), table); this.appEvents.trigger('composer:insert-text', table);
handled = true; handled = true;
} }
} }
const placeholder = `${ plainText || I18n.t('pasting') }`;
if (html && !handled) { if (html && !handled) {
const self = this; const self = this;
@ -671,9 +672,8 @@ export default Ember.Component.extend({
}).then(response => { }).then(response => {
self.appEvents.trigger('composer:replace-text', placeholder, response.markdown); self.appEvents.trigger('composer:replace-text', placeholder, response.markdown);
}).catch(error => { }).catch(error => {
if (plainText) { if (!plainText) {
self.appEvents.trigger('composer:replace-text', placeholder, plainText); self.appEvents.trigger('composer:replace-text', placeholder, "");
} else {
popupAjaxError(error); popupAjaxError(error);
} }
}); });