Skip to content

Commit 10b9bec

Browse files
committed
fix: ignore empty runs
1 parent e4e5fbb commit 10b9bec

4 files changed

Lines changed: 54 additions & 1 deletion

File tree

packages/super-editor/src/editors/v1/core/layout-adapter/converters/paragraph.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,44 @@ describe('getLastParagraphFont', () => {
352352
const result = getLastParagraphFont(blocks);
353353
expect(result).toBeUndefined();
354354
});
355+
356+
it('skips empty first runs even when they carry stale font values', () => {
357+
const blocks: FlowBlock[] = [
358+
{
359+
kind: 'paragraph',
360+
id: '0-paragraph',
361+
runs: [
362+
{
363+
kind: 'text',
364+
text: 'Valid',
365+
fontFamily: 'ValidFont',
366+
fontSize: 11,
367+
pmStart: 0,
368+
pmEnd: 5,
369+
},
370+
],
371+
attrs: {},
372+
},
373+
{
374+
kind: 'paragraph',
375+
id: '1-paragraph',
376+
runs: [
377+
{
378+
kind: 'text',
379+
text: '',
380+
fontFamily: 'StaleFont',
381+
fontSize: 42,
382+
pmStart: 5,
383+
pmEnd: 5,
384+
},
385+
],
386+
attrs: {},
387+
},
388+
];
389+
390+
const result = getLastParagraphFont(blocks);
391+
expect(result).toEqual({ fontFamily: 'ValidFont', fontSize: 11 });
392+
});
355393
});
356394

357395
describe('paragraph converters', () => {

packages/super-editor/src/editors/v1/core/layout-adapter/converters/paragraph.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,10 @@ export function getLastParagraphFont(blocks: FlowBlock[]): ParagraphFont | undef
10771077
const para = block as ParagraphBlock;
10781078
const firstRun = para.runs?.[0];
10791079
if (!firstRun) continue;
1080-
const run = firstRun as { fontFamily?: string; fontSize?: number };
1080+
const run = firstRun as { text?: string; fontFamily?: string; fontSize?: number };
1081+
if (typeof run.text === 'string' && run.text.length === 0) {
1082+
continue;
1083+
}
10811084
const fontFamily = typeof run.fontFamily === 'string' ? run.fontFamily.trim() : '';
10821085
const fontSize = typeof run.fontSize === 'number' && Number.isFinite(run.fontSize) ? run.fontSize : NaN;
10831086
if (fontFamily.length > 0 && fontSize > 0) {

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)