This commit is contained in:
djmaze 2020-09-30 17:11:06 +02:00
parent cfdbe3251e
commit 0eea2cb5ad
2 changed files with 12 additions and 11 deletions

View file

@ -437,7 +437,7 @@ export function htmlToPlain(html) {
} }
} }
return text.replace(/__bq__start__/gm, '').replace(/__bq__end__/gm, ''); return text.replace(/__bq__start__|__bq__end__/gm, '').trim();
} }
/** /**

View file

@ -17,6 +17,9 @@ const doc = document,
tpl = doc.createElement('template'), tpl = doc.createElement('template'),
clr = doc.createElement('input'), clr = doc.createElement('input'),
trimLines = html => html.trim().replace(/^(<div>\s*<br\s*\/?>\s*<\/div>)+/, '').trim(),
clearHtmlLine = html => rl.Utils.htmlToPlain(html).trim(),
getFragmentOfChildren = parent => { getFragmentOfChildren = parent => {
let frag = doc.createDocumentFragment(); let frag = doc.createDocumentFragment();
frag.append(...parent.childNodes); frag.append(...parent.childNodes);
@ -81,9 +84,7 @@ const doc = document,
let let
prevSignature = editor.__previous_signature, prevSignature = editor.__previous_signature,
skipInsert = false, skipInsert = false,
isEmptyText = false, isEmptyText = false;
newLine = (isHtml ? '<br />' : "\n"),
clearHtmlLine = html => rl.Utils.htmlToPlain(html).trim();
isEmptyText = !text.trim(); isEmptyText = !text.trim();
if (!isEmptyText && isHtml) { if (!isEmptyText && isHtml) {
@ -115,14 +116,14 @@ const doc = document,
} else { } else {
var textLen = text.length; var textLen = text.length;
text = text text = text
.replace('' + prevSignature.body, '') .replace(prevSignature.body, '')
.replace('' + prevSignature.body, ''); .replace(prevSignature.body, '');
skipInsert = textLen === text.length; skipInsert = textLen === text.length;
} }
} }
if (!skipInsert) { if (!skipInsert) {
signature = newLine + newLine + (isHtml ? '<signature>' : '') + signature + (isHtml ? '</signature>' : ''); signature = (isHtml ? '<br/><br/><signature>' : "\n\n") + signature + (isHtml ? '</signature>' : '');
text = insertBefore ? signature + text : text + signature; text = insertBefore ? signature + text : text + signature;
@ -500,7 +501,7 @@ class SquireUI
this.plain.value = rl.Utils.htmlToPlain(html, true).trim(); this.plain.value = rl.Utils.htmlToPlain(html, true).trim();
} else { } else {
let plain = this.plain.value; let plain = this.plain.value;
this.squire.setHTML(rl.Utils.plainToHtml(plain, true)); this.setData(rl.Utils.plainToHtml(plain, true));
mode = 'wysiwyg'; mode = 'wysiwyg';
} }
this.mode = mode; // 'wysiwyg' or 'plain' this.mode = mode; // 'wysiwyg' or 'plain'
@ -540,7 +541,7 @@ class SquireUI
if (!cfg.isHtml) { if (!cfg.isHtml) {
cfg.signature = rl.Utils.plainToHtml(cfg.signature); cfg.signature = rl.Utils.plainToHtml(cfg.signature);
} }
this.squire.setHTML(rl_signature_replacer(this, this.getData(), cfg.signature, true, cfg.insertBefore)); this.setData(rl_signature_replacer(this, this.getData(), cfg.signature, true, cfg.insertBefore));
} }
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -549,11 +550,11 @@ class SquireUI
} }
getData() { getData() {
return this.squire.getHTML(); return trimLines(this.squire.getHTML());
} }
setData(html) { setData(html) {
this.squire.setHTML(html); this.squire.setHTML(trimLines(html));
} }
focus() { focus() {