5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-10-05 05:16:56 +00:00

prevenir loop infinito arreglando poner párrafos automágicamente cuando no los hay

This commit is contained in:
void 2020-11-16 16:31:52 -03:00
parent 4107267e5b
commit c646ad3fe0

View file

@ -236,6 +236,14 @@ function cleanContent (contentEl) {
} else if (!elementIsBlock(child)) { } else if (!elementIsBlock(child)) {
child.tagName = "P" 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á * * Wrappea el contenido de un UL o OL en un LI si no lo está
*/ */
function fixContent (contentEl) { function fixContent (contentEl) {
if (!contentEl.firstChild) {
const newEl = document.createElement("p")
contentEl.appendChild(newEl)
window.getSelection().collapse(newEl)
}
for (const child of contentEl.childNodes) { for (const child of contentEl.childNodes) {
if (child.tagName) { if (child.tagName) {
if (elementIsParentBlock(child)) { if (elementIsParentBlock(child)) {