🐛 Fix paste RTF crashes text editor (#7196)

This commit is contained in:
Aitor Moreno
2025-08-28 11:53:39 +02:00
committed by GitHub
parent a20bbeff79
commit 884b857d17
3 changed files with 10 additions and 5 deletions

View File

@@ -31,7 +31,7 @@
- Fix consistency issues on how font variants are visualized [Taiga #11499](https://tree.taiga.io/project/penpot/us/11499) - 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) - 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 ## 2.9.0

View File

@@ -517,8 +517,8 @@ export class TextEditor extends EventTarget {
} }
} }
export function createRootFromHTML(html, style) { export function createRootFromHTML(html, style = undefined) {
const fragment = mapContentFragmentFromHTML(html, style); const fragment = mapContentFragmentFromHTML(html, style || undefined);
const root = createRoot([], style); const root = createRoot([], style);
root.replaceChildren(fragment); root.replaceChildren(fragment);
resetInertElement(); resetInertElement();

View File

@@ -9,8 +9,10 @@
import { getFills } from "./Color.js"; import { getFills } from "./Color.js";
const DEFAULT_FONT_SIZE = "16px"; const DEFAULT_FONT_SIZE = "16px";
const DEFAULT_FONT_SIZE_VALUE = parseFloat(DEFAULT_FONT_SIZE);
const DEFAULT_LINE_HEIGHT = "1.2"; const DEFAULT_LINE_HEIGHT = "1.2";
const DEFAULT_FONT_WEIGHT = "400"; const DEFAULT_FONT_WEIGHT = "400";
/** /**
* Merges two style declarations. `source` -> `target`. * Merges two style declarations. `source` -> `target`.
* *
@@ -220,10 +222,13 @@ export function setStyle(element, styleName, styleValue, styleUnit) {
*/ */
function getStyleFontSize(styleValueAsNumber, styleValue) { function getStyleFontSize(styleValueAsNumber, styleValue) {
if (styleValue.endsWith("pt")) { if (styleValue.endsWith("pt")) {
return (styleValueAsNumber * 1.3333).toFixed(); const baseSize = 1.3333;
return (styleValueAsNumber * baseSize).toFixed();
} else if (styleValue.endsWith("em")) { } else if (styleValue.endsWith("em")) {
const baseSize = DEFAULT_FONT_SIZE_VALUE;
return (styleValueAsNumber * baseSize).toFixed(); return (styleValueAsNumber * baseSize).toFixed();
} else if (styleValue.endsWith("%")) { } else if (styleValue.endsWith("%")) {
const baseSize = DEFAULT_FONT_SIZE_VALUE;
return ((styleValueAsNumber / 100) * baseSize).toFixed(); return ((styleValueAsNumber / 100) * baseSize).toFixed();
} }
return styleValueAsNumber.toFixed(); return styleValueAsNumber.toFixed();