From 95545783c6fa386c9ed8d52416ca083f6a4255b6 Mon Sep 17 00:00:00 2001 From: vhuseinova-msft <98852890+vhuseinova-msft@users.noreply.github.com> Date: Thu, 9 May 2024 13:38:32 -0700 Subject: [PATCH 1/2] Updated isModelEmptyFast --- .../lib/watermark/isModelEmptyFast.ts | 5 ++++ .../test/watermark/isModelEmptyFastTest.ts | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/packages/roosterjs-content-model-plugins/lib/watermark/isModelEmptyFast.ts b/packages/roosterjs-content-model-plugins/lib/watermark/isModelEmptyFast.ts index bf78a5b03eb..4265e799e34 100644 --- a/packages/roosterjs-content-model-plugins/lib/watermark/isModelEmptyFast.ts +++ b/packages/roosterjs-content-model-plugins/lib/watermark/isModelEmptyFast.ts @@ -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 } diff --git a/packages/roosterjs-content-model-plugins/test/watermark/isModelEmptyFastTest.ts b/packages/roosterjs-content-model-plugins/test/watermark/isModelEmptyFastTest.ts index dac437b0c1a..e45d8a4e3a9 100644 --- a/packages/roosterjs-content-model-plugins/test/watermark/isModelEmptyFastTest.ts +++ b/packages/roosterjs-content-model-plugins/test/watermark/isModelEmptyFastTest.ts @@ -99,6 +99,30 @@ describe('isModelEmptyFast', () => { expect(result).toBeTrue(); }); + it('Single Paragraph block - right margin 10px', () => { + const model = createContentModelDocument(); + const para = createParagraph(); + para.format.marginRight = '10px'; + + 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'; + + model.blocks.push(para); + + const result = isModelEmptyFast(model); + + expect(result).toBeFalse(); + }); + it('Single Paragraph block - two BR segment', () => { const model = createContentModelDocument(); const para = createParagraph(); From 56dfccfbe9ff65d34cafba0e99979595acd9ed11 Mon Sep 17 00:00:00 2001 From: vhuseinova-msft <98852890+vhuseinova-msft@users.noreply.github.com> Date: Thu, 9 May 2024 14:24:04 -0700 Subject: [PATCH 2/2] Tests fix --- .../test/watermark/isModelEmptyFastTest.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/roosterjs-content-model-plugins/test/watermark/isModelEmptyFastTest.ts b/packages/roosterjs-content-model-plugins/test/watermark/isModelEmptyFastTest.ts index e45d8a4e3a9..0549fb805ae 100644 --- a/packages/roosterjs-content-model-plugins/test/watermark/isModelEmptyFastTest.ts +++ b/packages/roosterjs-content-model-plugins/test/watermark/isModelEmptyFastTest.ts @@ -104,6 +104,7 @@ describe('isModelEmptyFast', () => { const para = createParagraph(); para.format.marginRight = '10px'; + para.segments.push(createBr()); model.blocks.push(para); const result = isModelEmptyFast(model); @@ -116,6 +117,7 @@ describe('isModelEmptyFast', () => { const para = createParagraph(); para.format.marginLeft = '0.25rem'; + para.segments.push(createBr()); model.blocks.push(para); const result = isModelEmptyFast(model);