Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(docs): no need to cache font style when has no text run (#3779)

Ran Luo8a4847935523
diff --git a/packages/engine-render/src/components/docs/layout/tools.ts b/packages/engine-render/src/components/docs/layout/tools.ts
index 69a5e239f3..6b43f42609 100644
--- a/packages/engine-render/src/components/docs/layout/tools.ts
+++ b/packages/engine-render/src/components/docs/layout/tools.ts
@@ -802,6 +802,8 @@ function getBulletParagraphTextStyle(bullet: IBullet, viewModel: DocumentViewMod
return lists[listType].nestingLevel[0].paragraphProperties?.textStyle;
}
+const DEFAULT_TEXT_RUN = { ts: {}, st: 0, ed: 0 };
+
export function getFontCreateConfig(
index: number,
viewModel: DocumentViewModel,
@@ -825,21 +827,22 @@ export function getFontCreateConfig(
const { paragraphStyle = {}, bullet } = paragraph;
const { isRenderStyle } = renderConfig;
const { startIndex } = paragraphNode;
+ const originTextRun = viewModel.getTextRun(index + startIndex);
const textRun = isRenderStyle === BooleanNumber.FALSE
- ? { ts: {}, st: 0, ed: 0 }
- : viewModel.getTextRun(index + startIndex) || { ts: {}, st: 0, ed: 0 };
+ ? DEFAULT_TEXT_RUN
+ : originTextRun ?? DEFAULT_TEXT_RUN;
const customDecoration = viewModel.getCustomDecoration(index + startIndex);
const showCustomDecoration = customDecoration && (customDecoration.show !== false);
const customDecorationStyle = showCustomDecoration ? getCustomDecorationStyle(customDecoration) : null;
const customRange = viewModel.getCustomRange(index + startIndex);
const showCustomRange = customRange && (customRange.show !== false);
const customRangeStyle = showCustomRange ? getCustomRangeStyle(customRange) : null;
- const hasAddonStyle = showCustomRange || showCustomDecoration;
+ const hasAddonStyle = showCustomRange || showCustomDecoration || !!bullet;
const { st, ed } = textRun;
let { ts: textStyle = {} } = textRun;
const cache = fontCreateConfigCache.getValue(st, ed);
- if (cache && !hasAddonStyle) {
+ if (cache && !hasAddonStyle && originTextRun) {
return cache;
}
@@ -872,8 +875,8 @@ export function getFontCreateConfig(
pageWidth,
};
- if (!hasAddonStyle) {
- // TODO: cache should more precisely, take custom-range, custom-decroation, paragraphStyle into considering.
+ if (!hasAddonStyle && originTextRun) {
+ // TODO: cache should more precisely, take custom-range, custom-decoration, paragraphStyle into considering.
fontCreateConfigCache.setValue(st, ed, result);
}