From 3c479f91dc34c8aaf886de1f142bd0bf5c34d772 Mon Sep 17 00:00:00 2001 From: void Date: Mon, 9 Nov 2020 14:35:57 -0300 Subject: [PATCH] =?UTF-8?q?probar=20borrando=20l=C3=B3gica=20custom=20de?= =?UTF-8?q?=20evento=20de=20enter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit si genera bugs lo revertimos --- app/assets/javascripts/02-editor.js | 40 +---------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/app/assets/javascripts/02-editor.js b/app/assets/javascripts/02-editor.js index c3676794..e737ca9d 100644 --- a/app/assets/javascripts/02-editor.js +++ b/app/assets/javascripts/02-editor.js @@ -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)