Skip to content

Commit

Permalink
Do not increase list number that starts from 1 (#2766)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Aug 14, 2024
1 parent c5d5de9 commit 97e65dd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export const listLevelThreadFormatHandler: FormatHandler<ListThreadFormat> = {
const depth = levels.length;

if (
typeof threadItemCounts[depth] === 'number' &&
element.start != threadItemCounts[depth] + 1
element.start == 1 ||
(typeof threadItemCounts[depth] === 'number' &&
element.start != threadItemCounts[depth] + 1)
) {
format.startNumberOverride = element.start;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,15 @@ describe('childProcessor', () => {
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
levels: [{ listType: 'OL', format: {}, dataset: {} }],
levels: [
{
listType: 'OL',
format: {
startNumberOverride: 1,
},
dataset: {},
},
],
formatHolder: { segmentType: 'SelectionMarker', isSelected: false, format: {} },
blocks: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('listProcessor', () => {
childProcessor.and.callFake((group, parent, context) => {
expect(context.listFormat.listParent).toBe(group);
expect(context.listFormat.levels).toEqual([
{ listType: 'OL', format: {}, dataset: {} },
{ listType: 'OL', format: { startNumberOverride: 1 }, dataset: {} },
]);
expect(context.listFormat.threadItemCounts).toEqual([0]);
expect(context.segmentFormat).toEqual({});
Expand Down Expand Up @@ -88,7 +88,13 @@ describe('listProcessor', () => {
childProcessor.and.callFake((group, parent, context) => {
expect(context.listFormat.listParent).toBe(group);
expect(context.listFormat.levels).toEqual([
{ listType: 'OL', format: {}, dataset: {} },
{
listType: 'OL',
format: {
startNumberOverride: 1,
},
dataset: {},
},
]);
expect(context.listFormat.threadItemCounts).toEqual([0]);
expect(context.segmentFormat).toEqual({
Expand Down Expand Up @@ -212,6 +218,7 @@ describe('listProcessor', () => {
paddingBottom: '2px',
paddingLeft: '2px',
listStylePosition: 'inside',
startNumberOverride: 1,
},
dataset: {},
},
Expand Down Expand Up @@ -254,6 +261,7 @@ describe('listProcessor', () => {
marginBottom: '0px',
marginLeft: '0px',
marginRight: '0px',
startNumberOverride: 1,
},
dataset: {},
},
Expand Down Expand Up @@ -468,7 +476,7 @@ describe('listProcessor process metadata', () => {
expect(context.listFormat.levels).toEqual([
{
listType: 'OL',
format: {},
format: { startNumberOverride: 1 },
dataset: {},
},
]);
Expand All @@ -492,7 +500,7 @@ describe('listProcessor process metadata', () => {
expect(context.listFormat.levels).toEqual([
{
listType: 'OL',
format: {},
format: { startNumberOverride: 1 },
dataset: {
editingInfo: JSON.stringify({ orderedStyleType: 1, unorderedStyleType: 2 }),
},
Expand Down Expand Up @@ -520,7 +528,7 @@ describe('listProcessor process metadata', () => {
expect(context.listFormat.levels).toEqual([
{
listType: 'OL',
format: {},
format: { startNumberOverride: 1 },
dataset: { editingInfo: metadata },
},
]);
Expand All @@ -544,7 +552,7 @@ describe('listProcessor process metadata', () => {
expect(context.listFormat.levels).toEqual([
{
listType: 'OL',
format: {},
format: { startNumberOverride: 1 },
dataset: {
editingInfo: JSON.stringify({
orderedStyleType: NumberingListType.Max,
Expand Down Expand Up @@ -576,7 +584,7 @@ describe('listProcessor process metadata', () => {
{
listType: 'OL',
dataset: { editingInfo },
format: {},
format: { startNumberOverride: 1 },
},
]);
});
Expand All @@ -601,6 +609,7 @@ describe('listProcessor process metadata', () => {
listType: 'OL',
format: {
listStyleType: 'decimal',
startNumberOverride: 1,
},
dataset: {
editingInfo: JSON.stringify({ orderedStyleType: NumberingListType.Max }),
Expand Down Expand Up @@ -640,6 +649,7 @@ describe('listProcessor process metadata', () => {
dataset: {},
format: {
direction: 'rtl',
startNumberOverride: 1,
},
},
],
Expand Down
10 changes: 6 additions & 4 deletions packages/roosterjs-content-model-dom/test/endToEndTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ describe('End to end test for DOM => Model => DOM/TEXT', () => {
isImplicit: true,
},
],
levels: [{ listType: 'OL', format: {}, dataset: {} }],
levels: [
{ listType: 'OL', format: { startNumberOverride: 1 }, dataset: {} },
],
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: false,
Expand All @@ -228,7 +230,7 @@ describe('End to end test for DOM => Model => DOM/TEXT', () => {
],
levels: [
{ listType: 'OL', format: {}, dataset: {} },
{ listType: 'OL', format: {}, dataset: {} },
{ listType: 'OL', format: { startNumberOverride: 1 }, dataset: {} },
],
formatHolder: {
segmentType: 'SelectionMarker',
Expand Down Expand Up @@ -2139,12 +2141,12 @@ describe('End to end test for DOM => Model => DOM/TEXT', () => {
levels: [
{
listType: 'OL',
format: {},
format: { startNumberOverride: 1 },
dataset: {},
},
{
listType: 'OL',
format: { listStyleType: '"1) "' },
format: { listStyleType: '"1) "', startNumberOverride: 1 },
dataset: {},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('listLevelThreadFormatHandler.parse', () => {

listLevelThreadFormatHandler.parse(format, ol, context, {});

expect(format.startNumberOverride).toBeUndefined();
expect(format.startNumberOverride).toBe(1);
expect(context.listFormat).toEqual({
threadItemCounts: [0],
levels: [],
Expand All @@ -38,7 +38,7 @@ describe('listLevelThreadFormatHandler.parse', () => {

listLevelThreadFormatHandler.parse(format, ol, context, {});

expect(format.startNumberOverride).toBeUndefined();
expect(format.startNumberOverride).toBe(1);
expect(context.listFormat).toEqual({
threadItemCounts: [0],
levels: [],
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('listLevelThreadFormatHandler.parse', () => {

listLevelThreadFormatHandler.parse(format, ol, context, {});

expect(format.startNumberOverride).toBeUndefined();
expect(format.startNumberOverride).toBe(1);
expect(context.listFormat).toEqual({
threadItemCounts: [2, 0],
levels: [
Expand Down

0 comments on commit 97e65dd

Please sign in to comment.