From feddf96f2a97ebc58f33386d8bb2e58412b7e961 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Tue, 26 Jan 2021 23:42:04 +0100 Subject: [PATCH] Change logic to detect inline elements, as the display style property may not be set after setting innerHTML --- qt/aqt/data/web/js/editor.ts | 64 +++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/qt/aqt/data/web/js/editor.ts b/qt/aqt/data/web/js/editor.ts index dc47a011c..e906bc4f6 100644 --- a/qt/aqt/data/web/js/editor.ts +++ b/qt/aqt/data/web/js/editor.ts @@ -117,14 +117,68 @@ function nodeIsText(node: Node): node is Text { return node.nodeType === Node.TEXT_NODE; } +const INLINE_TAGS = [ + "A", + "ABBR", + "ACRONYM", + "AUDIO", + "B", + "BDI", + "BDO", + "BIG", + "BR", + "BUTTON", + "CANVAS", + "CITE", + "CODE", + "DATA", + "DATALIST", + "DEL", + "DFN", + "EM", + "EMBED", + "I", + "IFRAME", + "IMG", + "INPUT", + "INS", + "KBD", + "LABEL", + "MAP", + "MARK", + "METER", + "NOSCRIPT", + "OBJECT", + "OUTPUT", + "PICTURE", + "PROGRESS", + "Q", + "RUBY", + "S", + "SAMP", + "SCRIPT", + "SELECT", + "SLOT", + "SMALL", + "SPAN", + "STRONG", + "SUB", + "SUP", + "SVG", + "TEMPLATE", + "TEXTAREA", + "TIME", + "U", + "TT", + "VAR", + "VIDEO", + "WBR", +]; + function nodeIsInline(node: Node): boolean { return ( nodeIsText(node) || - nodeIsBRElement(node) || - window - .getComputedStyle(node as Element) - .getPropertyValue("display") - .startsWith("inline") + INLINE_TAGS.includes((node as Element).tagName) ); }