mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-15 06:21:41 +00:00
probar borrando lógica custom de evento de enter
si genera bugs lo revertimos
This commit is contained in:
parent
5018574b27
commit
3c479f91dc
1 changed files with 1 additions and 39 deletions
|
@ -320,45 +320,7 @@ function setupEditor (editorEl) {
|
|||
const contentEl = editorEl.querySelector(".editor-content")
|
||||
|
||||
contentEl.addEventListener("keydown", event => {
|
||||
if (event.keyCode === 13) { // Enter
|
||||
event.preventDefault()
|
||||
const sel = window.getSelection()
|
||||
|
||||
let parentEl = sel.anchorNode
|
||||
if (parentEl == contentEl) {
|
||||
const newEl = document.createElement("p")
|
||||
contentEl.appendChild(newEl)
|
||||
sel.collapse(newEl)
|
||||
} else if (contentEl.contains(parentEl)) {
|
||||
while ((parentEl.nodeType == Node.TEXT_NODE || !elementIsBlock(parentEl)) && parentEl != contentEl)
|
||||
parentEl = parentEl.parentElement
|
||||
|
||||
if (parentEl == contentEl) parentEl = parentEl.firstChild
|
||||
|
||||
let newEl
|
||||
switch (parentEl.tagName) {
|
||||
case "UL":
|
||||
case "OL":
|
||||
let itemEl = sel.anchorNode
|
||||
while (itemEl.tagName !== "LI" && parentEl.contains(itemEl))
|
||||
itemEl = itemEl.parentElement
|
||||
|
||||
if (!parentEl.contains(itemEl)) itemEl = null
|
||||
|
||||
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:
|
||||
newEl = document.createElement("p")
|
||||
contentEl.insertBefore(newEl, parentEl.nextSibling)
|
||||
}
|
||||
|
||||
sel.collapse(newEl)
|
||||
}
|
||||
} else if (event.keyCode === 32) { // Espacio
|
||||
if (event.keyCode === 32) { // Espacio
|
||||
event.preventDefault()
|
||||
const sel = window.getSelection()
|
||||
const range = sel.getRangeAt(0)
|
||||
|
|
Loading…
Reference in a new issue