From 6c69ef914d720cd32165345ec5f4cbb8efcfc02b Mon Sep 17 00:00:00 2001 From: vhuseinova-msft <98852890+vhuseinova-msft@users.noreply.github.com> Date: Thu, 9 May 2024 16:00:13 -0700 Subject: [PATCH] Updated isModelEmptyFast to consider changed indentation as not empty string (#2625) * Updated isModelEmptyFast * Tests fix --- .../lib/watermark/isModelEmptyFast.ts | 5 ++++ .../test/watermark/isModelEmptyFastTest.ts | 26 +++++++++++++++++++ 2 files changed, 31 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..0549fb805ae 100644 --- a/packages/roosterjs-content-model-plugins/test/watermark/isModelEmptyFastTest.ts +++ b/packages/roosterjs-content-model-plugins/test/watermark/isModelEmptyFastTest.ts @@ -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();