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(engine-render): continue numbering across list levels (#7614)

wpxp123456524a9aa357ac
diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/__tests__/linebreaking.spec.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/__tests__/linebreaking.spec.ts
index a25b9b0320..fd62e9bda5 100644
--- a/packages/engine-render/src/components/docs/layout/block/paragraph/__tests__/linebreaking.spec.ts
+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/__tests__/linebreaking.spec.ts
@@ -24,6 +24,7 @@ import {
DocumentFlavor,
GridType,
HorizontalAlign,
+ ListGlyphType,
ObjectRelativeFromH,
ObjectRelativeFromV,
PositionedObjectLayoutType,
@@ -1364,6 +1365,60 @@ describe('linebreaking', () => {
expect(result.length).toBeGreaterThanOrEqual(1);
});
+ it('continues numbering when the first paragraph starts at a deeper level', () => {
+ const { viewModel, ctx, sectionNode, sectionBreakConfig, curPage } = createSectionLayoutTestBed(
+ ['Section', 'Article', 'Article', 'Article'],
+ {
+ body: {
+ paragraphs: [
+ { startIndex: 7, bullet: { listId: 'list-1', listType: 'legal-list', nestingLevel: 1 } },
+ { startIndex: 15, bullet: { listId: 'list-1', listType: 'legal-list', nestingLevel: 0 } },
+ { startIndex: 23, bullet: { listId: 'list-1', listType: 'legal-list', nestingLevel: 0 } },
+ { startIndex: 31, bullet: { listId: 'list-1', listType: 'legal-list', nestingLevel: 0 } },
+ ],
+ },
+ lists: {
+ 'legal-list': {
+ listType: 'legal-list',
+ nestingLevel: [
+ {
+ glyphFormat: 'Article %1.',
+ glyphType: ListGlyphType.UPPER_ROMAN,
+ startNumber: 0,
+ bulletAlignment: 1,
+ },
+ {
+ glyphFormat: 'Section %1.%2',
+ glyphType: ListGlyphType.DECIMAL_ZERO,
+ startNumber: 0,
+ bulletAlignment: 1,
+ isLegal: true,
+ },
+ ],
+ },
+ },
+ }
+ );
+
+ let page = curPage;
+ const symbols: string[] = [];
+ for (const paragraphNode of sectionNode.children) {
+ const pages = lineBreaking(
+ ctx,
+ viewModel,
+ shaping(ctx, paragraphNode.content!, viewModel, paragraphNode, sectionBreakConfig),
+ page,
+ paragraphNode,
+ sectionBreakConfig,
+ null
+ );
+ page = pages[pages.length - 1];
+ symbols.push(ctx.paragraphConfigCache.get(page.segmentId)?.get(paragraphNode.endIndex)?.bulletSkeleton?.symbol ?? '');
+ }
+
+ expect(symbols).toEqual(['Section 1.01', 'Article II.', 'Article III.', 'Article IV.']);
+ });
+
it('aligns wrapped list lines with the body text after the hanging marker', () => {
const content = 'A wrapped list item with enough text to continue';
const { viewModel, ctx, paragraphNode, sectionBreakConfig, curPage } = createParagraphLayoutTestBed(content, {
diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/linebreaking.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/linebreaking.ts
index 3b90b606d1..cf377cde8c 100644
--- a/packages/engine-render/src/components/docs/layout/block/paragraph/linebreaking.ts
+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/linebreaking.ts
@@ -21,6 +21,7 @@ import type {
IDocumentBody,
IDocumentStyle,
IDrawings,
+ ILists,
IParagraph,
IParagraphStyle,
Nullable,
@@ -269,7 +270,8 @@ function _updateListLevelAncestors(
paragraph: IParagraph,
bullet?: IBullet,
bulletSkeleton?: IDocumentSkeletonBullet,
- listLevel?: Map<string, IParagraphList[][]>
+ listLevel?: Map<string, IParagraphList[][]>,
+ lists?: ILists
) {
if (!bullet || !bulletSkeleton) {
return;
@@ -279,6 +281,22 @@ function _updateListLevelAncestors(
const cacheItem: IParagraphList[][] = [...(listLevel?.get(listId) || [])];
+ const nestingLevels = lists?.[bullet.listType]?.nestingLevel;
+ for (let level = 0; level < nestingLevel; level++) {
+ if (cacheItem[level]?.length || nestingLevels?.[level] == null) {
+ continue;
+ }
+
+ cacheItem[level] = [{
+ bullet: {
+ ...bulletSkeleton,
+ startIndexItem: 2,
+ startNumber: nestingLevels[level].startNumber,
+ },
+ paragraph,
+ }];
+ }
+
// [[nestingLevel, bulletSkeleton]];
if (cacheItem[nestingLevel] == null) {
@@ -837,7 +855,7 @@ export function lineBreaking(
const listLevelAncestors = _getListLevelAncestors(bullet, skeListLevel); // Get the cache of all levels of the list
const bulletSkeleton = dealWithBullet(bullet, lists, listLevelAncestors, localeService); // Generate bullet
- _updateListLevelAncestors(paragraph, bullet, bulletSkeleton, skeListLevel); // Update the latest level cache list
+ _updateListLevelAncestors(paragraph, bullet, bulletSkeleton, skeListLevel, lists); // Update the latest level cache list
paragraphConfig.bulletSkeleton = bulletSkeleton;
}