Skip to content

Commit

Permalink
Fix 227982 (#2095)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Sep 25, 2023
1 parent 13efdf6 commit d9e8e89
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,14 @@ export function setListType(model: ContentModelDocument, listType: 'OL' | 'UL')
}

function shouldIgnoreBlock(block: ContentModelBlock) {
return (
block.blockType != 'Paragraph' ||
block.segments.every(x => x.segmentType == 'Br' || x.segmentType == 'SelectionMarker')
);
switch (block.blockType) {
case 'Table':
return false;
case 'Paragraph':
return block.segments.every(
x => x.segmentType == 'Br' || x.segmentType == 'SelectionMarker'
);
default:
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
createListItem,
createListLevel,
createParagraph,
createTable,
createTableCell,
createText,
} from 'roosterjs-content-model-dom';

Expand Down Expand Up @@ -540,6 +542,115 @@ describe('indent', () => {
});
});

it('do not turn on list for table', () => {
const group = createContentModelDocument();
const para1 = createParagraph();
const table = createTable(1);
const para2 = createParagraph();
const text1 = createText('test1');
const text2 = createText('test2');
const cell = createTableCell();

para1.segments.push(text1);
para2.segments.push(text2);
table.rows[0].cells.push(cell);
group.blocks.push(para1, table, para2);

text1.isSelected = true;
text2.isSelected = true;
cell.isSelected = true;

const result = setListType(group, 'OL');

expect(result).toBeTrue();
expect(group).toEqual({
blockGroupType: 'Document',
blocks: [
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [para1],
levels: [
{
listType: 'OL',
dataset: {},
format: {
startNumberOverride: 1,
direction: undefined,
textAlign: undefined,
marginTop: undefined,
},
},
],
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: true,
format: {
fontFamily: undefined,
fontSize: undefined,
textColor: undefined,
},
},
format: {},
},
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [table],
levels: [
{
listType: 'OL',
dataset: {},
format: {
startNumberOverride: undefined,
direction: undefined,
textAlign: undefined,
marginTop: undefined,
},
},
],
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: true,
format: {
fontFamily: undefined,
fontSize: undefined,
textColor: undefined,
},
},
format: {},
},
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [para2],
levels: [
{
listType: 'OL',
dataset: {},
format: {
marginTop: undefined,
direction: undefined,
textAlign: undefined,
startNumberOverride: undefined,
},
},
],
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: true,
format: {
fontFamily: undefined,
fontSize: undefined,
textColor: undefined,
},
},
format: {},
},
],
});
});

it('Change style type to existing list', () => {
const group = createContentModelDocument();
const list1 = createListItem([createListLevel('OL')]);
Expand Down

0 comments on commit d9e8e89

Please sign in to comment.