Skip to content

Commit cd68e21

Browse files
committed
fix: improve cached values for stale paragraph runs
1 parent 1012b28 commit cd68e21

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

packages/super-editor/src/editors/v1/core/layout-adapter/list-marker-font.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ describe('syncListMarkerFontFromParagraphRuns', () => {
155155

156156
expect(block.attrs.wordLayout?.marker?.run?.fontFamily).toContain('Georgia');
157157
expect(block.attrs.wordLayout?.marker?.run?.fontSize).toBe(30);
158+
expect(block.runs[0]?.fontFamily).toContain('Georgia');
159+
expect(block.runs[0]?.fontSize).toBe(30);
158160
});
159161

160162
it('does not fall back to stale cached runs on cache hits without textStyle or previousParagraphFont', () => {

packages/super-editor/src/editors/v1/core/layout-adapter/list-marker-font.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ export const syncListMarkerFontFromParagraphRuns = ({
134134
const contentFont = resolveContentFont(block, para, contentFontSource, previousParagraphFont);
135135
if (!contentFont) return;
136136

137+
// Cache-hit path may reuse stale empty runs. Normalize empty run font so subsequent
138+
// getLastParagraphFont() reads the current inherited font instead of cached values.
139+
if (contentFontSource === 'paragraph') {
140+
const firstRun = block.runs[0];
141+
if (firstRun && isTextRun(firstRun) && firstRun.text.length === 0) {
142+
if (contentFont.fontFamily) firstRun.fontFamily = contentFont.fontFamily;
143+
if (contentFont.fontSize) firstRun.fontSize = contentFont.fontSize;
144+
}
145+
}
146+
137147
const numberingOverrides = getNumberingMarkerFontOverrides(block.attrs?.numberingProperties, converterContext);
138148

139149
if (!numberingOverrides.fontFamily && contentFont.fontFamily) {

0 commit comments

Comments
 (0)