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 List bug fix #1320

Merged
merged 4 commits into from
Oct 11, 2022
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 @@ -22,13 +22,16 @@ export const listProcessor: ElementProcessor = (group, element, context) => {
parseFormat(element, ListLevelFormatHandlers, level, context);
parseFormat(element, SegmentFormatHandlers, context.segmentFormat, context);

const originalListParent = listFormat.listParent;

listFormat.listParent = listFormat.listParent || group;
listFormat.levels.push(level);

try {
containerProcessor(group, element, context);
} finally {
listFormat.levels.pop();
listFormat.listParent = originalListParent;
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ContentModelDocument } from '../../../lib/publicTypes/block/group/Conte
import { createContentModelDocument } from '../../../lib/modelApi/creators/createContentModelDocument';
import { createDomToModelContext } from '../../../lib/domToModel/context/createDomToModelContext';
import { DomToModelContext } from '../../../lib/publicTypes/context/DomToModelContext';
import { generalProcessor } from '../../../lib/domToModel/processors/generalProcessor';

describe('containerProcessor', () => {
let doc: ContentModelDocument;
Expand Down Expand Up @@ -290,4 +291,92 @@ describe('containerProcessor', () => {
isImplicit: true,
});
});

it('Process lists that are under different container', () => {
const div = document.createElement('div');
div.innerHTML =
'<div id="div1"><ol><li>test1</li></ol></div><div id="div2">test2</div><div id="div3"><ol><li>test3</li></ol></div>';

context.elementProcessors.DIV = generalProcessor;

containerProcessor(doc, div, context);

expect(doc.blocks.length).toBe(3);
expect(doc.blocks[0]).toEqual({
blockType: 'BlockGroup',
blockGroupType: 'General',
element: div.querySelector('#div1') as HTMLElement,
blocks: [
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
levels: [{ listType: 'OL' }],
formatHolder: { segmentType: 'SelectionMarker', isSelected: true, format: {} },
blocks: [
{
blockType: 'Paragraph',
isImplicit: true,
segments: [
{
segmentType: 'Text',
text: 'test1',
format: {},
},
],
},
],
},
],
});
expect(doc.blocks[1]).toEqual({
blockType: 'BlockGroup',
blockGroupType: 'General',
element: div.querySelector('#div2') as HTMLElement,
blocks: [
{
blockType: 'Paragraph',
isImplicit: true,
segments: [
{
segmentType: 'Text',
text: 'test2',
format: {},
},
],
},
],
});
expect(doc.blocks[2]).toEqual({
blockType: 'BlockGroup',
blockGroupType: 'General',
element: div.querySelector('#div3') as HTMLElement,
blocks: [
{
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
levels: [{ listType: 'OL', startNumberOverride: 1 }],
formatHolder: { segmentType: 'SelectionMarker', isSelected: true, format: {} },
blocks: [
{
blockType: 'Paragraph',
isImplicit: true,
segments: [
{
segmentType: 'Text',
text: 'test3',
format: {},
},
],
},
],
},
],
});

expect(context.listFormat).toEqual({
levels: [],
listParent: undefined,
threadItemCounts: [1],
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('listProcessor', () => {
blocks: [],
});

expect(context.listFormat.listParent).toBe(group);
expect(context.listFormat.listParent).toBeUndefined();
expect(context.listFormat.levels).toEqual([]);
expect(context.listFormat.threadItemCounts).toEqual([]);
expect(context.segmentFormat).toEqual({});
Expand All @@ -61,7 +61,7 @@ describe('listProcessor', () => {
blocks: [],
});

expect(context.listFormat.listParent).toBe(group);
expect(context.listFormat.listParent).toBeUndefined();
expect(context.listFormat.levels).toEqual([]);
expect(context.listFormat.threadItemCounts).toEqual([0]);
expect(context.segmentFormat).toEqual({});
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('listProcessor', () => {
blocks: [],
});

expect(context.listFormat.listParent).toBe(group);
expect(context.listFormat.listParent).toBeUndefined();
expect(context.listFormat.levels).toEqual([]);
expect(context.listFormat.threadItemCounts).toEqual([0]);
expect(context.segmentFormat).toEqual({});
Expand All @@ -116,7 +116,7 @@ describe('listProcessor', () => {
blocks: [],
});

expect(context.listFormat.listParent).toBe(group);
expect(context.listFormat.listParent).toBeUndefined();
expect(context.listFormat.levels).toEqual([]);
expect(context.listFormat.threadItemCounts).toEqual([]);
expect(context.segmentFormat).toEqual({});
Expand Down Expand Up @@ -153,7 +153,7 @@ describe('listProcessor', () => {
blocks: [],
});

expect(context.listFormat.listParent).toBe(group);
expect(context.listFormat.listParent).toBeUndefined();
expect(context.listFormat.threadItemCounts).toEqual([]);
expect(context.segmentFormat).toEqual({});

Expand Down Expand Up @@ -200,7 +200,7 @@ describe('listProcessor without format handlers', () => {
blocks: [],
});

expect(context.listFormat.listParent).toBe(group);
expect(context.listFormat.listParent).toBeUndefined();
expect(context.listFormat.levels).toEqual([]);
expect(context.listFormat.threadItemCounts).toEqual([]);
expect(context.segmentFormat).toEqual({});
Expand All @@ -225,7 +225,7 @@ describe('listProcessor without format handlers', () => {
blocks: [],
});

expect(context.listFormat.listParent).toBe(group);
expect(context.listFormat.listParent).toBeUndefined();
expect(context.listFormat.levels).toEqual([]);
expect(context.listFormat.threadItemCounts).toEqual([]);
expect(context.segmentFormat).toEqual({});
Expand Down Expand Up @@ -258,7 +258,7 @@ describe('listProcessor without format handlers', () => {
blocks: [],
});

expect(context.listFormat.listParent).toBe(group);
expect(context.listFormat.listParent).toBeUndefined();
expect(context.listFormat.levels).toEqual([]);
expect(context.listFormat.threadItemCounts).toEqual([]);
expect(context.segmentFormat).toEqual({});
Expand All @@ -280,7 +280,7 @@ describe('listProcessor without format handlers', () => {
blocks: [],
});

expect(context.listFormat.listParent).toBe(group);
expect(context.listFormat.listParent).toBeUndefined();
expect(context.listFormat.levels).toEqual([]);
expect(context.listFormat.threadItemCounts).toEqual([]);
expect(context.segmentFormat).toEqual({});
Expand Down Expand Up @@ -317,7 +317,7 @@ describe('listProcessor without format handlers', () => {
blocks: [],
});

expect(context.listFormat.listParent).toBe(group);
expect(context.listFormat.listParent).toBeUndefined();
expect(context.listFormat.threadItemCounts).toEqual([]);
expect(context.segmentFormat).toEqual({});

Expand Down