apretar dos enters para salir de una lista

This commit is contained in:
void 2020-11-06 11:26:58 -03:00
parent c926dcfe8f
commit a0e48a0cca
2 changed files with 13 additions and 6 deletions

View file

@ -322,16 +322,21 @@ function setupEditor (editorEl) {
switch (parentEl.tagName) { switch (parentEl.tagName) {
case "UL": case "UL":
case "OL": case "OL":
newEl = document.createElement("li")
let itemEl = sel.anchorNode let itemEl = sel.anchorNode
while (itemEl.tagName !== "LI" && parentEl.contains(itemEl)) itemEl = itemEl.parentElement while (itemEl.tagName !== "LI" && parentEl.contains(itemEl))
itemEl = itemEl.parentElement
parentEl.insertBefore(newEl, itemEl && parentEl.contains(itemEl) && itemEl.nextSibling || null) if (!parentEl.contains(itemEl)) itemEl = null
break
if (itemEl && hasContent(itemEl)) {
newEl = document.createElement("li")
parentEl.insertBefore(newEl, itemEl && itemEl.nextSibling)
break
}
// Fallthrough si es un li sin contenido, así salís de la lista
default: default:
newEl = document.createElement("p") newEl = document.createElement("p")
contentEl.insertBefore(newEl, parentEl.nextSibling || null) contentEl.insertBefore(newEl, parentEl.nextSibling)
} }
sel.collapse(newEl) sel.collapse(newEl)

View file

@ -25,6 +25,8 @@
margin: 0 auto; margin: 0 auto;
} }
ol, ul { margin: 0; }
.editor-content { .editor-content {
div[data-align="left"] { text-align: left; } div[data-align="left"] { text-align: left; }
div[data-align="center"] { text-align: center; } div[data-align="center"] { text-align: center; }