Skip to content

Commit

Permalink
Merge branch 'master' into u/jisong/cache8
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong committed Sep 20, 2023
2 parents a1866ea + 5cef7ba commit 2edc202
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { areSameFormats } from '../../domToModel/utils/areSameFormats';
import { ContentModelParagraph } from 'roosterjs-content-model-types';
import { createBr } from '../creators/createBr';
import { isSegmentEmpty } from './isEmpty';
import { isWhiteSpacePreserved } from './isWhiteSpacePreserved';
import { normalizeAllSegments } from './normalizeSegment';

/**
* @internal
*/
Expand Down Expand Up @@ -37,6 +37,8 @@ export function normalizeParagraph(paragraph: ContentModelParagraph) {
normalizeAllSegments(paragraph);
}

removeEmptyLinks(paragraph);

removeEmptySegments(paragraph);
}

Expand All @@ -47,3 +49,26 @@ function removeEmptySegments(block: ContentModelParagraph) {
}
}
}

function removeEmptyLinks(paragraph: ContentModelParagraph) {
const marker = paragraph.segments.find(x => x.segmentType == 'SelectionMarker');
if (marker) {
const markerIndex = paragraph.segments.indexOf(marker);
const prev = paragraph.segments[markerIndex - 1];
const next = paragraph.segments[markerIndex + 1];
if (
(prev &&
!prev.link &&
areSameFormats(prev.format, marker.format) &&
(!next || (!next.link && areSameFormats(next.format, marker.format))) &&
marker.link) ||
(!prev &&
marker.link &&
next &&
!next.link &&
areSameFormats(next.format, marker.format))
) {
delete marker.link;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,42 @@ describe('Normalize text that contains space', () => {
],
});
});

it('Remove empty links', () => {
const model = createContentModelDocument();
const para = createParagraph();
const marker = createSelectionMarker();
const text = createText('test');
marker.link = {
dataset: {},
format: {},
};

para.segments.push(text, marker);
model.blocks.push(para);

normalizeContentModel(model);

expect(model).toEqual({
blockGroupType: 'Document',
blocks: [
{
blockType: 'Paragraph',
format: {},
segments: [
{
segmentType: 'Text',
text: 'test',
format: {},
},
{
segmentType: 'SelectionMarker',
isSelected: true,
format: {},
},
],
},
],
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ export function alignTableCell(
return metadata;
});
}

cell.blocks.forEach(block => {
if (block.blockType === 'Paragraph') {
delete block.format.textAlign;
}
});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ describe('alignTableCell', () => {
expect(table.rows[1].cells[0].cachedElement).toEqual({} as any);
expect(table.rows[1].cells[1].cachedElement).toBeUndefined();
expect(table.rows[1].cells[2].cachedElement).toBeUndefined();
table.rows[0].cells[1].blocks.forEach(block => {
expect(block.format.textAlign).toEqual(undefined);
});
}

it('empty table', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ export default class ImageEdit implements EditorPlugin {
});

this.shadowSpan.style.verticalAlign = 'bottom';
this.shadowSpan.style.fontSize = '24px';
wrapper.style.fontSize = '24px';

shadowRoot.appendChild(wrapper);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe('ImageEdit | rotate and flip', () => {
editor.select(image);
plugin.setEditingImage(image, ImageEditOperation.Resize);
expect(editor.getContent()).toBe(
'<span style="vertical-align: bottom; font-size: 24px;"><img id="IMAGE_ID_EDITING" src="test"></span>'
'<span style="vertical-align: bottom;"><img id="IMAGE_ID_EDITING" src="test"></span>'
);
});
});
Expand Down

0 comments on commit 2edc202

Please sign in to comment.