Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content Model: Fix 227982 #2095

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading