From c646ad3fe000c96a38515f30106d5cd10d169884 Mon Sep 17 00:00:00 2001 From: void Date: Mon, 16 Nov 2020 16:31:52 -0300 Subject: [PATCH] =?UTF-8?q?prevenir=20loop=20infinito=20arreglando=20poner?= =?UTF-8?q?=20p=C3=A1rrafos=20autom=C3=A1gicamente=20cuando=20no=20los=20h?= =?UTF-8?q?ay?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/02-editor.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/02-editor.js b/app/assets/javascripts/02-editor.js index 78938408..7e27e269 100644 --- a/app/assets/javascripts/02-editor.js +++ b/app/assets/javascripts/02-editor.js @@ -236,6 +236,14 @@ function cleanContent (contentEl) { } else if (!elementIsBlock(child)) { child.tagName = "P" } + } else if (child.nodeType === Node.TEXT_NODE) { + const wasSelected = sel.getRangeAt(0).intersectsNode(child) + + const el = document.createElement("p") + el.appendChild(child) + contentEl.insertBefore(el, child.nextSibling) + + if (wasSelected) sel.collapse(el, child.data.length) } } } @@ -246,12 +254,6 @@ function cleanContent (contentEl) { * * Wrappea el contenido de un UL o OL en un LI si no lo está */ function fixContent (contentEl) { - if (!contentEl.firstChild) { - const newEl = document.createElement("p") - contentEl.appendChild(newEl) - window.getSelection().collapse(newEl) - } - for (const child of contentEl.childNodes) { if (child.tagName) { if (elementIsParentBlock(child)) {