From 0db8a14497624ffda7a4ceb97edb91f3dfe4cbc9 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Fri, 15 Jan 2021 18:18:42 +0100 Subject: [PATCH] Deal with div insertion on deleting list item --- qt/aqt/data/web/js/editor.ts | 44 ++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/qt/aqt/data/web/js/editor.ts b/qt/aqt/data/web/js/editor.ts index bf3ea9dd7..d56b71071 100644 --- a/qt/aqt/data/web/js/editor.ts +++ b/qt/aqt/data/web/js/editor.ts @@ -57,7 +57,6 @@ function onKey(evt: KeyboardEvent) { // prefer
instead of
if (evt.which === 13 && !inListItem()) { - console.log("Enter"); evt.preventDefault(); document.execCommand("insertLineBreak"); return; @@ -88,6 +87,23 @@ function onKey(evt: KeyboardEvent) { triggerKeyTimer(); } +function onKeyUp(evt: KeyboardEvent) { + // Avoid div element on remove + if (evt.which === 8 || evt.which === 13) { + const anchor = window.getSelection().anchorNode; + + if ( + nodeIsElement(anchor) && + anchor.tagName === "DIV" && + !anchor.classList.contains("field") && + anchor.childElementCount === 1 && + anchor.children[0].tagName === "BR" + ) { + anchor.replaceWith(anchor.children[0]); + } + } +} + function nodeIsElement(node: Node): node is Element { return node.nodeType == Node.ELEMENT_NODE; } @@ -364,19 +380,19 @@ function setFields(fields) { -
${f}
`;