From a0e48a0ccaa7a160cf7b6ea466845f5ecc7cc1b3 Mon Sep 17 00:00:00 2001 From: void Date: Fri, 6 Nov 2020 11:26:58 -0300 Subject: [PATCH] apretar dos enters para salir de una lista --- app/assets/javascripts/02-editor.js | 17 +++++++++++------ app/assets/stylesheets/editor.scss | 2 ++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/02-editor.js b/app/assets/javascripts/02-editor.js index 5e5b1a0..a6e7254 100644 --- a/app/assets/javascripts/02-editor.js +++ b/app/assets/javascripts/02-editor.js @@ -322,16 +322,21 @@ function setupEditor (editorEl) { switch (parentEl.tagName) { case "UL": case "OL": - newEl = document.createElement("li") - 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) - break + 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 || null) + contentEl.insertBefore(newEl, parentEl.nextSibling) } sel.collapse(newEl) diff --git a/app/assets/stylesheets/editor.scss b/app/assets/stylesheets/editor.scss index cc96492..f2f2eaa 100644 --- a/app/assets/stylesheets/editor.scss +++ b/app/assets/stylesheets/editor.scss @@ -25,6 +25,8 @@ margin: 0 auto; } + ol, ul { margin: 0; } + .editor-content { div[data-align="left"] { text-align: left; } div[data-align="center"] { text-align: center; }