Skip to content

Commit 367e2d8

Browse files
authored
Fix type error when continuing list (#3149)
* type error * list types
1 parent 13bded5 commit 367e2d8

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

packages/roosterjs-content-model-plugins/lib/autoFormat/list/getListTypeStyle.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,10 @@ const getPreviousListLevel = (
131131
};
132132

133133
const getPreviousListStyle = (list?: ContentModelListItem) => {
134-
if (list?.levels[0].dataset) {
135-
return updateListMetadata(list.levels[0])?.orderedStyleType;
134+
if (!list || list.levels.length < 1) {
135+
return undefined;
136136
}
137+
return updateListMetadata(list.levels[0])?.orderedStyleType;
137138
};
138139

139140
const bulletListType: Map<string, number> = new Map<string, number>([

packages/roosterjs-content-model-plugins/test/autoFormat/list/getListTypeStyleTest.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,4 +1356,59 @@ describe('getListTypeStyle', () => {
13561356
index: 3,
13571357
});
13581358
});
1359+
1360+
it('should create a new list', () => {
1361+
const model: ContentModelDocument = {
1362+
blockGroupType: 'Document',
1363+
blocks: [
1364+
{
1365+
formatHolder: {
1366+
isSelected: false,
1367+
segmentType: 'SelectionMarker',
1368+
format: {},
1369+
},
1370+
levels: [],
1371+
blockType: 'BlockGroup',
1372+
format: {},
1373+
blockGroupType: 'ListItem',
1374+
blocks: [
1375+
{
1376+
segments: [
1377+
{
1378+
segmentType: 'Br',
1379+
format: {},
1380+
},
1381+
],
1382+
segmentFormat: {},
1383+
blockType: 'Paragraph',
1384+
format: {},
1385+
},
1386+
],
1387+
},
1388+
{
1389+
segments: [
1390+
{
1391+
text: '1.',
1392+
segmentType: 'Text',
1393+
format: {},
1394+
},
1395+
{
1396+
isSelected: true,
1397+
segmentType: 'SelectionMarker',
1398+
format: {},
1399+
},
1400+
],
1401+
segmentFormat: {},
1402+
blockType: 'Paragraph',
1403+
format: {},
1404+
},
1405+
],
1406+
format: {},
1407+
};
1408+
runTest(model, {
1409+
listType: 'OL',
1410+
styleType: NumberingListType.Decimal,
1411+
index: undefined,
1412+
});
1413+
});
13591414
});

0 commit comments

Comments
 (0)