🐛 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

@@ -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

View File

@@ -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();

View File

@@ -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();