From 1a4594a6153fe2038ba6f4da5fe7accc31759d71 Mon Sep 17 00:00:00 2001 From: Aitor Moreno Date: Tue, 9 Sep 2025 10:41:55 +0200 Subject: [PATCH] :bug: Fix text editor v1 paste HTML --- .../src/editor/content/dom/Content.js | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/frontend/text-editor/src/editor/content/dom/Content.js b/frontend/text-editor/src/editor/content/dom/Content.js index 8b3f1e8e69..aa550e9724 100644 --- a/frontend/text-editor/src/editor/content/dom/Content.js +++ b/frontend/text-editor/src/editor/content/dom/Content.js @@ -14,6 +14,11 @@ import { } from "./Paragraph.js"; import { isDisplayBlock, normalizeStyles } from "./Style.js"; +const DEFAULT_FONT_SIZE = "14px"; +const DEFAULT_FONT_WEIGHT = 400; +const DEFAULT_FONT_FAMILY = "sourcesanspro"; +const DEFAULT_FILLS = '[["^ ","~:fill-color", "#000000","~:fill-opacity", 1]]'; + /** * Returns if the content fragment should be treated as * inline content and not a paragraphed one. @@ -72,11 +77,26 @@ export function mapContentFragmentFromDocument(document, root, styleDefaults) { } const inline = createInline(new Text(currentNode.nodeValue), currentStyle); const fontSize = inline.style.getPropertyValue("font-size"); - if (!fontSize) console.warn("font-size", fontSize); + if (!fontSize) { + console.warn("font-size", fontSize); + inline.style.setProperty("font-size", styleDefaults?.getPropertyValue("font-size") ?? DEFAULT_FONT_SIZE); + } const fontFamily = inline.style.getPropertyValue("font-family"); - if (!fontFamily) console.warn("font-family", fontFamily); + if (!fontFamily) { + console.warn("font-family", fontFamily); + inline.style.setProperty("font-family", styleDefaults?.getPropertyValue("font-family") ?? DEFAULT_FONT_FAMILY); + } const fontWeight = inline.style.getPropertyValue("font-weight"); - if (!fontWeight) console.warn("font-weight", fontWeight); + if (!fontWeight) { + console.warn("font-weight", fontWeight); + inline.style.setProperty("font-weight", styleDefaults?.getPropertyValue("font-weight") ?? DEFAULT_FONT_WEIGHT) + } + const fills = inline.style.getPropertyValue('--fills'); + if (!fills) { + console.warn("fills", fills); + inline.style.setProperty("--fills", styleDefaults?.getPropertyValue("--fills") ?? DEFAULT_FILLS); + } + currentParagraph.appendChild(inline); currentNode = nodeIterator.nextNode();