Skip to content

Commit

Permalink
Merge branch 'master' into u/jisong/2861_2862
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Nov 20, 2024
2 parents 010b288 + 486ea52 commit 4797113
Show file tree
Hide file tree
Showing 3 changed files with 354 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function getListTypeStyle(
if (bulletType && shouldSearchForBullet) {
return { listType: 'UL', styleType: bulletType };
} else if (shouldSearchForNumbering) {
const previousList = getPreviousListLevel(model, paragraph);
const { previousList, hasSpaceBetween } = getPreviousListLevel(model, paragraph);
const previousIndex = getPreviousListIndex(model, previousList);
const previousListStyle = getPreviousListStyle(previousList);
const numberingType = getNumberingListStyle(
Expand All @@ -64,19 +64,35 @@ export function getListTypeStyle(
return {
listType: 'OL',
styleType: numberingType,
index:
!isNewList(listMarker) &&
previousListStyle === numberingType &&
previousIndex
? previousIndex + 1
: undefined,
index: getIndex(
listMarker,
previousListStyle,
numberingType,
previousIndex,
hasSpaceBetween
),
};
}
}
}
return undefined;
}

const getIndex = (
listMarker: string,
previousListStyle?: number,
numberingType?: number,
previousIndex?: number,
hasSpaceBetween?: boolean
) => {
const newList = isNewList(listMarker);
return previousListStyle && previousListStyle !== numberingType && newList
? 1
: !newList && previousListStyle === numberingType && hasSpaceBetween && previousIndex
? previousIndex + 1
: undefined;
};

const getPreviousListIndex = (
model: ReadonlyContentModelDocument,
previousListItem?: ReadonlyContentModelListItem
Expand All @@ -93,22 +109,25 @@ const getPreviousListLevel = (
['ListItem'],
['TableCell']
)[0];
let listItem: ContentModelListItem | undefined = undefined;
let previousList: ContentModelListItem | undefined = undefined;
let hasSpaceBetween = false;
if (blocks) {
const listBlockIndex = blocks.parent.blocks.indexOf(paragraph);

if (listBlockIndex > -1) {
for (let i = listBlockIndex - 1; i > -1; i--) {
const item = blocks.parent.blocks[i];
if (isBlockGroupOfType<ContentModelListItem>(item, 'ListItem')) {
listItem = item;
previousList = item;
break;
} else {
hasSpaceBetween = listBlockIndex > 0 ? true : false;
}
}
}
}

return listItem;
return { previousList, hasSpaceBetween };
};

const getPreviousListStyle = (list?: ContentModelListItem) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const triggerList = (
) => {
setListType(model, listType);
const isOrderedList = listType == 'OL';
if (index && index > 1 && isOrderedList) {
if (index && index > 0 && isOrderedList) {
setModelListStartNumber(model, index);
}
setModelListStyle(
Expand Down
Loading

0 comments on commit 4797113

Please sign in to comment.