Skip to content

Commit f8b190e

Browse files
committed
fix: preserve explicit numbering
1 parent 1382336 commit f8b190e

2 files changed

Lines changed: 80 additions & 8 deletions

File tree

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

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ describe('syncListMarkerFontFromParagraphRuns', () => {
139139
expect(block.attrs.wordLayout?.marker?.run?.fontSize).toBe(40);
140140
});
141141

142-
it('preserves numbering-defined marker font family but still syncs font size', () => {
142+
it('preserves numbering-defined marker font family but still syncs font size when size is unset', () => {
143143
const block = listBlock({
144144
runs: [{ text: 'item', fontFamily: 'Georgia, serif', fontSize: 30 }],
145145
markerFamily: 'Symbol',
@@ -152,6 +152,75 @@ describe('syncListMarkerFontFromParagraphRuns', () => {
152152
expect(block.attrs.wordLayout?.marker?.run?.fontSize).toBe(30);
153153
});
154154

155+
it('preserves numbering-defined marker font size from w:sz', () => {
156+
const sizedSymbolContext = {
157+
...symbolContext,
158+
translatedNumbering: {
159+
definitions: { '1': { numId: 1, abstractNumId: 1 } },
160+
abstracts: {
161+
'1': {
162+
abstractNumId: 1,
163+
levels: {
164+
'0': {
165+
ilvl: 0,
166+
runProperties: {
167+
fontFamily: { ascii: 'Symbol' },
168+
fontSize: 20,
169+
},
170+
},
171+
},
172+
},
173+
},
174+
},
175+
};
176+
177+
const block = listBlock({
178+
runs: [{ text: 'item', fontFamily: 'Georgia, serif', fontSize: 30 }],
179+
markerFamily: 'Symbol',
180+
markerSize: 10,
181+
markerText: '•',
182+
});
183+
184+
syncListMarkerFontFromParagraphRuns({ block, converterContext: sizedSymbolContext as never });
185+
186+
expect(block.attrs.wordLayout?.marker?.run?.fontFamily).toContain('Symbol');
187+
expect(block.attrs.wordLayout?.marker?.run?.fontSize).toBe(10);
188+
});
189+
190+
it('preserves numbering-defined marker font size from w:szCs', () => {
191+
const sizedSymbolContext = {
192+
...symbolContext,
193+
translatedNumbering: {
194+
definitions: { '1': { numId: 1, abstractNumId: 1 } },
195+
abstracts: {
196+
'1': {
197+
abstractNumId: 1,
198+
levels: {
199+
'0': {
200+
ilvl: 0,
201+
runProperties: {
202+
fontFamily: { ascii: 'Symbol' },
203+
fontSizeCs: 20,
204+
},
205+
},
206+
},
207+
},
208+
},
209+
},
210+
};
211+
212+
const block = listBlock({
213+
runs: [{ text: 'item', fontFamily: 'Georgia, serif', fontSize: 30 }],
214+
markerFamily: 'Symbol',
215+
markerSize: 10,
216+
markerText: '•',
217+
});
218+
219+
syncListMarkerFontFromParagraphRuns({ block, converterContext: sizedSymbolContext as never });
220+
221+
expect(block.attrs.wordLayout?.marker?.run?.fontSize).toBe(10);
222+
});
223+
155224
it('reads numbering from block attrs on cache hits so Symbol font is preserved', () => {
156225
const block = listBlock({
157226
runs: [{ text: 'item', fontFamily: 'Georgia, serif', fontSize: 40 }],

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,20 @@ const resolveContentFont = (
9494
return source === 'paragraph' ? mergeContentFont(fromPara, fromRuns) : (fromRuns ?? fromPara);
9595
};
9696

97-
const numberingDefinesMarkerFontFamily = (
97+
const getNumberingMarkerFontOverrides = (
9898
numberingProperties: { numId?: number; ilvl?: number } | null | undefined,
9999
converterContext?: ConverterContext,
100-
): boolean => {
100+
): { fontFamily: boolean; fontSize: boolean } => {
101101
const numId = numberingProperties?.numId;
102102
if (numId == null || numId === 0 || !converterContext) {
103-
return false;
103+
return { fontFamily: false, fontSize: false };
104104
}
105105
const ilvl = numberingProperties?.ilvl ?? 0;
106106
const numberingRunProps = getNumberingProperties<RunProperties>('runProperties', converterContext, ilvl, numId);
107-
return numberingRunProps.fontFamily != null;
107+
return {
108+
fontFamily: numberingRunProps.fontFamily != null,
109+
fontSize: numberingRunProps.fontSize != null || numberingRunProps.fontSizeCs != null,
110+
};
108111
};
109112

110113
/**
@@ -122,12 +125,12 @@ export const syncListMarkerFontFromParagraphRuns = ({
122125
const contentFont = resolveContentFont(block, para, contentFontSource);
123126
if (!contentFont) return;
124127

125-
const preserveMarkerFontFamily = numberingDefinesMarkerFontFamily(block.attrs?.numberingProperties, converterContext);
128+
const numberingOverrides = getNumberingMarkerFontOverrides(block.attrs?.numberingProperties, converterContext);
126129

127-
if (!preserveMarkerFontFamily && contentFont.fontFamily) {
130+
if (!numberingOverrides.fontFamily && contentFont.fontFamily) {
128131
markerRun.fontFamily = contentFont.fontFamily;
129132
}
130-
if (contentFont.fontSize) {
133+
if (!numberingOverrides.fontSize && contentFont.fontSize) {
131134
markerRun.fontSize = contentFont.fontSize;
132135
}
133136
};

0 commit comments

Comments
 (0)