Skip to content

Commit

Permalink
Merge branch 'master' into u/jisong/cmcontentchanged
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Sep 18, 2023
2 parents 6d9708f + e8e0462 commit 0e5f504
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function mergeModel(

switch (block.blockType) {
case 'Paragraph':
mergeParagraph(insertPosition, block, i == 0, context);
mergeParagraph(insertPosition, block, i == 0, context, options);
break;

case 'Divider':
Expand Down Expand Up @@ -125,14 +125,21 @@ function mergeParagraph(
markerPosition: InsertPoint,
newPara: ContentModelParagraph,
mergeToCurrentParagraph: boolean,
context?: FormatWithContentModelContext
context?: FormatWithContentModelContext,
option?: MergeModelOption
) {
const { paragraph, marker } = markerPosition;
const newParagraph = mergeToCurrentParagraph
? paragraph
: splitParagraph(markerPosition, newPara.format);
const segmentIndex = newParagraph.segments.indexOf(marker);

if (option?.mergeFormat == 'none' && mergeToCurrentParagraph) {
newParagraph.segments.forEach(segment => {
segment.format = { ...(newParagraph.segmentFormat || {}), ...segment.format };
});
delete newParagraph.segmentFormat;
}
if (segmentIndex >= 0) {
for (let i = 0; i < newPara.segments.length; i++) {
const segment = newPara.segments[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,109 @@ describe('mergeModel', () => {
});
});

it('Merge with default format paragraph and paragraph, mergeFormat: none', () => {
const MockedFormat = {
fontFamily: 'sourceSegmentFormatFontFamily',
italic: 'sourceSegmentFormatItalic',
underline: 'sourceSegmentFormatUnderline',
fontSize: 'sourceSegmentFormatFontSize',
} as any;
const majorModel = createContentModelDocument(MockedFormat);
majorModel.blocks.push({
blockType: 'Paragraph',
segmentFormat: MockedFormat,
segments: [
{
segmentType: 'Text',
text: 'test',
format: {
fontFamily: 'sourceFontFamily',
} as any,
},
createSelectionMarker(),
],
format: {},
});
const sourceModel: ContentModelDocument = {
blockGroupType: 'Document',
blocks: [
{
blockType: 'Paragraph',
segments: [
{
segmentType: 'Text',
text: 'test',
format: {
fontFamily: 'sourceFontFamily',
italic: 'sourceItalic',
underline: 'sourceUnderline',
fontSize: 'sourcefontSize',
} as any,
},
],
format: {},
},
],
};
const para1 = createParagraph();
const marker = createSelectionMarker();

para1.segments.push(marker);
majorModel.blocks.push(para1);

mergeModel(
majorModel,
sourceModel,
{ newEntities: [], deletedEntities: [] },
{
mergeFormat: 'none',
}
);

expect(majorModel).toEqual({
blockGroupType: 'Document',
blocks: [
{
blockType: 'Paragraph',
segments: [
Object({
segmentType: 'Text',
text: 'test',
format: Object({
fontFamily: 'sourceFontFamily',
italic: 'sourceSegmentFormatItalic',
underline: 'sourceSegmentFormatUnderline',
fontSize: 'sourceSegmentFormatFontSize',
}),
}),
Object({
segmentType: 'Text',
text: 'test',
format: Object({
fontFamily: 'sourceFontFamily',
italic: 'sourceItalic',
underline: 'sourceUnderline',
fontSize: 'sourcefontSize',
}),
}),
Object({
segmentType: 'SelectionMarker',
isSelected: true,
format: Object({
fontFamily: 'sourceSegmentFormatFontFamily',
italic: 'sourceSegmentFormatItalic',
underline: 'sourceSegmentFormatUnderline',
fontSize: 'sourceSegmentFormatFontSize',
}),
}),
],
format: {},
},
],
format: MockedFormat,
});
});

it('Merge Table + Paragraph', () => {
const majorModel = createContentModelDocument();
const sourceModel: ContentModelDocument = {
Expand Down

0 comments on commit 0e5f504

Please sign in to comment.