Skip to content

Commit

Permalink
Updated isModelEmptyFast to consider changed indentation as not empty…
Browse files Browse the repository at this point in the history
… string (#2625)

* Updated isModelEmptyFast

* Tests fix
  • Loading branch information
vhuseinova-msft authored May 9, 2024
1 parent 8d2aa9f commit 6c69ef9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export function isModelEmptyFast(model: ContentModelDocument): boolean {
)
) {
return false; // Has meaningful segments, it is not empty
} else if (
(firstBlock.format.marginRight && parseFloat(firstBlock.format.marginRight) > 0) ||
(firstBlock.format.marginLeft && parseFloat(firstBlock.format.marginLeft) > 0)
) {
return false; // Has margin (indentation is changed), it is not empty
} else {
return firstBlock.segments.filter(x => x.segmentType == 'Br').length <= 1; // If there are more than one BR, it is not empty, otherwise it is empty
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,32 @@ describe('isModelEmptyFast', () => {
expect(result).toBeTrue();
});

it('Single Paragraph block - right margin 10px', () => {
const model = createContentModelDocument();
const para = createParagraph();
para.format.marginRight = '10px';

para.segments.push(createBr());
model.blocks.push(para);

const result = isModelEmptyFast(model);

expect(result).toBeFalse();
});

it('Single Paragraph block - left margin 0.25rem', () => {
const model = createContentModelDocument();
const para = createParagraph();
para.format.marginLeft = '0.25rem';

para.segments.push(createBr());
model.blocks.push(para);

const result = isModelEmptyFast(model);

expect(result).toBeFalse();
});

it('Single Paragraph block - two BR segment', () => {
const model = createContentModelDocument();
const para = createParagraph();
Expand Down

0 comments on commit 6c69ef9

Please sign in to comment.