mirror of
https://github.com/penpot/penpot.git
synced 2025-05-03 11:45:54 +02:00
🐛 Fix pasted text loses font-family style (#5808)
This commit is contained in:
parent
7eefbc5979
commit
db55c06c67
2 changed files with 9 additions and 5 deletions
|
@ -73,10 +73,11 @@ export function mapContentFragmentFromDocument(document, root, styleDefaults) {
|
||||||
currentParagraph = createParagraph(undefined, currentStyle);
|
currentParagraph = createParagraph(undefined, currentStyle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const inline = createInline(new Text(currentNode.nodeValue), currentStyle);
|
const inline = createInline(new Text(currentNode.nodeValue), currentStyle);
|
||||||
const fontSize = inline.style.getPropertyValue("font-size");
|
const fontSize = inline.style.getPropertyValue("font-size");
|
||||||
if (!fontSize) console.warn("font-size", fontSize);
|
if (!fontSize) console.warn("font-size", fontSize);
|
||||||
|
const fontFamily = inline.style.getPropertyValue("font-family");
|
||||||
|
if (!fontFamily) console.warn("font-family", fontFamily);
|
||||||
currentParagraph.appendChild(inline);
|
currentParagraph.appendChild(inline);
|
||||||
|
|
||||||
currentNode = nodeIterator.nextNode();
|
currentNode = nodeIterator.nextNode();
|
||||||
|
|
|
@ -23,7 +23,8 @@ export function mergeStyleDeclarations(target, source) {
|
||||||
// for (const styleName of source) {
|
// for (const styleName of source) {
|
||||||
for (let index = 0; index < source.length; index++) {
|
for (let index = 0; index < source.length; index++) {
|
||||||
const styleName = source.item(index);
|
const styleName = source.item(index);
|
||||||
target.setProperty(styleName, source.getPropertyValue(styleName));
|
const styleValue = source.getPropertyValue(styleName);
|
||||||
|
target.setProperty(styleName, styleValue);
|
||||||
}
|
}
|
||||||
return target
|
return target
|
||||||
}
|
}
|
||||||
|
@ -108,9 +109,10 @@ export function getComputedStyle(element) {
|
||||||
inertElement.style.setProperty(styleName, newValue);
|
inertElement.style.setProperty(styleName, newValue);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const newValue = currentElement.style.getPropertyValue(styleName);
|
||||||
inertElement.style.setProperty(
|
inertElement.style.setProperty(
|
||||||
styleName,
|
styleName,
|
||||||
currentElement.style.getPropertyValue(styleName)
|
newValue
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,9 +132,10 @@ export function getComputedStyle(element) {
|
||||||
* @returns {CSSStyleDeclaration}
|
* @returns {CSSStyleDeclaration}
|
||||||
*/
|
*/
|
||||||
export function normalizeStyles(node, styleDefaults = getStyleDefaultsDeclaration()) {
|
export function normalizeStyles(node, styleDefaults = getStyleDefaultsDeclaration()) {
|
||||||
|
const computedStyle = getComputedStyle(node.parentElement);
|
||||||
const styleDeclaration = mergeStyleDeclarations(
|
const styleDeclaration = mergeStyleDeclarations(
|
||||||
styleDefaults,
|
styleDefaults,
|
||||||
getComputedStyle(node.parentElement)
|
computedStyle
|
||||||
);
|
);
|
||||||
|
|
||||||
// If there's a color property, we should convert it to
|
// If there's a color property, we should convert it to
|
||||||
|
@ -149,7 +152,7 @@ export function normalizeStyles(node, styleDefaults = getStyleDefaultsDeclaratio
|
||||||
// If there's a font-family property and not a --font-id, then
|
// If there's a font-family property and not a --font-id, then
|
||||||
// we remove the font-family because it will not work.
|
// we remove the font-family because it will not work.
|
||||||
const fontFamily = styleDeclaration.getPropertyValue("font-family");
|
const fontFamily = styleDeclaration.getPropertyValue("font-family");
|
||||||
const fontId = styleDeclaration.getPropertyPriority("--font-id");
|
const fontId = styleDeclaration.getPropertyValue("--font-id");
|
||||||
if (fontFamily && !fontId) {
|
if (fontFamily && !fontId) {
|
||||||
styleDeclaration.removeProperty("font-family");
|
styleDeclaration.removeProperty("font-family");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue