5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-15 08:21:41 +00:00

borrar LIs cuando no hay una lista

This commit is contained in:
void 2020-11-06 11:48:37 -03:00
parent a0e48a0cca
commit 766d3c407c

View file

@ -224,7 +224,7 @@ function hasContent (element) {
function cleanContent (contentEl) {
const sel = window.getSelection()
cleanNode(contentEl)
cleanNode(contentEl, contentEl)
for (const child of contentEl.childNodes) {
if (child.tagName) {
@ -258,6 +258,7 @@ function fixContent (contentEl) {
for (const item of child.childNodes) {
if (item.tagName !== "LI") notItems.push(item)
}
if (notItems.length) {
const item = document.createElement("li")
item.append(...notItems)
@ -274,7 +275,7 @@ function fixContent (contentEl) {
* * Junta nodos de la misma "mark" que están al lado
* * Borra elementos sin contenido (ver `hasContent`) y no están seleccionados
*/
function cleanNode (node) {
function cleanNode (node, contentEl) {
for (const child of node.childNodes) {
if (child.nodeType === Node.TEXT_NODE) {
if (child.nextSibling && child.nextSibling.nodeType === Node.TEXT_NODE) {
@ -292,8 +293,26 @@ function cleanNode (node) {
child.nextSibling.parentNode.removeChild(child.nextSibling)
}
}
if (child.tagName === "LI") {
let parentEl = child
while (
parentEl
&& !(parentEl.nodeType == Node.ELEMENT_NODE && elementIsBlock(parentEl))
&& contentEl.contains(parentEl)
)
parentEl = parentEl.parentElement
if (
parentEl
&& contentEl.contains(parentEl)
&& parentEl.tagName !== "UL"
&& parentEl.tagName !== "OL"
)
moveChildren(child, parentEl, child.nextSibling)
}
}
cleanNode(child)
cleanNode(child, contentEl)
}
}
@ -316,8 +335,6 @@ function setupEditor (editorEl) {
if (parentEl == contentEl) parentEl = parentEl.firstChild
console.log(parentEl)
let newEl
switch (parentEl.tagName) {
case "UL":