From 884b857d170dcde4879445780f37f0bc47826b66 Mon Sep 17 00:00:00 2001 From: Aitor Moreno Date: Thu, 28 Aug 2025 11:53:39 +0200 Subject: [PATCH] :bug: Fix paste RTF crashes text editor (#7196) --- CHANGES.md | 4 ++-- frontend/text-editor/src/editor/TextEditor.js | 4 ++-- frontend/text-editor/src/editor/content/dom/Style.js | 7 ++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 569ddf65d5..8ebb8b981b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -30,8 +30,8 @@ - Fix issue where Alt + arrow keys shortcut interferes with letter-spacing when moving text layers [Taiga #11552](https://tree.taiga.io/project/penpot/issue/11771) - Fix consistency issues on how font variants are visualized [Taiga #11499](https://tree.taiga.io/project/penpot/us/11499) - Fix parsing rx and ry SVG values for rect radius [Taiga #11861](https://tree.taiga.io/project/penpot/issue/11861) -- Misleading affordance in saved versions [Taiga #11887](https://tree.taiga.io/project/penpot/issue/11887) - +- Misleading affordance in saved versions [Taiga #11887](https://tree.taiga.io/project/penpot/issue/11887) +- Fix pasting RTF text crashes penpot [Taiga #11717](https://tree.taiga.io/project/penpot/issue/11717) ## 2.9.0 diff --git a/frontend/text-editor/src/editor/TextEditor.js b/frontend/text-editor/src/editor/TextEditor.js index 09fddb1d59..f440092ce3 100644 --- a/frontend/text-editor/src/editor/TextEditor.js +++ b/frontend/text-editor/src/editor/TextEditor.js @@ -517,8 +517,8 @@ export class TextEditor extends EventTarget { } } -export function createRootFromHTML(html, style) { - const fragment = mapContentFragmentFromHTML(html, style); +export function createRootFromHTML(html, style = undefined) { + const fragment = mapContentFragmentFromHTML(html, style || undefined); const root = createRoot([], style); root.replaceChildren(fragment); resetInertElement(); diff --git a/frontend/text-editor/src/editor/content/dom/Style.js b/frontend/text-editor/src/editor/content/dom/Style.js index 7b6bca9162..14313a7ce5 100644 --- a/frontend/text-editor/src/editor/content/dom/Style.js +++ b/frontend/text-editor/src/editor/content/dom/Style.js @@ -9,8 +9,10 @@ import { getFills } from "./Color.js"; const DEFAULT_FONT_SIZE = "16px"; +const DEFAULT_FONT_SIZE_VALUE = parseFloat(DEFAULT_FONT_SIZE); const DEFAULT_LINE_HEIGHT = "1.2"; const DEFAULT_FONT_WEIGHT = "400"; + /** * Merges two style declarations. `source` -> `target`. * @@ -220,10 +222,13 @@ export function setStyle(element, styleName, styleValue, styleUnit) { */ function getStyleFontSize(styleValueAsNumber, styleValue) { if (styleValue.endsWith("pt")) { - return (styleValueAsNumber * 1.3333).toFixed(); + const baseSize = 1.3333; + return (styleValueAsNumber * baseSize).toFixed(); } else if (styleValue.endsWith("em")) { + const baseSize = DEFAULT_FONT_SIZE_VALUE; return (styleValueAsNumber * baseSize).toFixed(); } else if (styleValue.endsWith("%")) { + const baseSize = DEFAULT_FONT_SIZE_VALUE; return ((styleValueAsNumber / 100) * baseSize).toFixed(); } return styleValueAsNumber.toFixed();