From 54d349c4e131414ccc6d3a2b8c2eaefd2c3ad10a Mon Sep 17 00:00:00 2001 From: martgil Date: Thu, 26 Sep 2024 15:55:36 +0800 Subject: [PATCH 1/5] Added checks for RichText() before initializing squire --- .../chrome/elements/compose-modules/compose-input-module.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extension/chrome/elements/compose-modules/compose-input-module.ts b/extension/chrome/elements/compose-modules/compose-input-module.ts index 9e34237a238..97691cc7800 100644 --- a/extension/chrome/elements/compose-modules/compose-input-module.ts +++ b/extension/chrome/elements/compose-modules/compose-input-module.ts @@ -40,7 +40,9 @@ export class ComposeInputModule extends ViewModule { 'click', this.view.setHandler(el => this.actionAddIntroHandler(el), this.view.errModule.handle(`add intro`)) ); - this.initSquire(this.isRichText()); + if (this.isRichText()) { + this.initSquire(true); + } // Set lastDraftBody to current empty squire content ex:

) // https://github.com/FlowCrypt/flowcrypt-browser/issues/5184 this.view.draftModule.setLastDraftBody(this.squire.getHTML()); From 061beedefb83e178ed5f2cb19ad5c8a1bfb50b96 Mon Sep 17 00:00:00 2001 From: martgil Date: Thu, 26 Sep 2024 19:11:49 +0800 Subject: [PATCH 2/5] fix failing test --- test/source/tests/compose.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/source/tests/compose.ts b/test/source/tests/compose.ts index 44c7a78ca14..bd2e4df9034 100644 --- a/test/source/tests/compose.ts +++ b/test/source/tests/compose.ts @@ -1686,7 +1686,7 @@ export const defineComposeTests = (testVariant: TestVariant, testWithBrowser: Te expect(await composePage.read('.swal2-html-container')).to.include('Send empty message?'); await composePage.waitAndClick('.swal2-cancel'); const footer = await composePage.read('@input-body'); - expect(footer).to.eq('\n\n\n\n--\n\nflowcrypt.compatibility test footer with an img\n\nand second line\n'); + expect(footer).to.eq('\n\n\n--\nflowcrypt.compatibility test footer with an img\nand second line'); await composePage.waitAndClick(`@action-send`); expect(await composePage.read('.swal2-html-container')).to.include('Send empty message?'); await composePage.waitAndClick('.swal2-cancel'); From fb7af2df6fa232e22947544452141a776ee73404 Mon Sep 17 00:00:00 2001 From: martgil Date: Fri, 27 Sep 2024 18:13:36 +0800 Subject: [PATCH 3/5] pr review: fix squire initialization --- .../elements/compose-modules/compose-input-module.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/extension/chrome/elements/compose-modules/compose-input-module.ts b/extension/chrome/elements/compose-modules/compose-input-module.ts index 97691cc7800..f53e5431a7d 100644 --- a/extension/chrome/elements/compose-modules/compose-input-module.ts +++ b/extension/chrome/elements/compose-modules/compose-input-module.ts @@ -36,13 +36,11 @@ export class ComposeInputModule extends ViewModule { } public setHandlers = () => { + this.toggleRichTextFormatting(); this.view.S.cached('add_intro').on( 'click', this.view.setHandler(el => this.actionAddIntroHandler(el), this.view.errModule.handle(`add intro`)) ); - if (this.isRichText()) { - this.initSquire(true); - } // Set lastDraftBody to current empty squire content ex:

) // https://github.com/FlowCrypt/flowcrypt-browser/issues/5184 this.view.draftModule.setLastDraftBody(this.squire.getHTML()); @@ -107,6 +105,14 @@ export class ComposeInputModule extends ViewModule { return isInputLimitExceeded; }; + private toggleRichTextFormatting = () => { + if (this.isRichText()) { + this.addRichTextFormatting(); + } else { + this.removeRichTextFormatting(); + } + }; + private initSquire = (addLinks: boolean, removeExistingLinks = false) => { const squireHtml = this.squire?.getHTML(); const el = this.view.S.cached('input_text').get(0); From bc7548741f7b967a4660d5fce7f522f95c89d40c Mon Sep 17 00:00:00 2001 From: martgil Date: Fri, 27 Sep 2024 18:23:30 +0800 Subject: [PATCH 4/5] refactor --- .../chrome/elements/compose-modules/compose-input-module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/chrome/elements/compose-modules/compose-input-module.ts b/extension/chrome/elements/compose-modules/compose-input-module.ts index f53e5431a7d..eb3aa1ec9e4 100644 --- a/extension/chrome/elements/compose-modules/compose-input-module.ts +++ b/extension/chrome/elements/compose-modules/compose-input-module.ts @@ -54,7 +54,7 @@ export class ComposeInputModule extends ViewModule { }; public removeRichTextFormatting = () => { - if (this.view.inputModule.isRichText()) { + if (this.isRichText()) { this.initSquire(false, true); } }; From 4a41603a3f74c71d049625766325c8b7a8fafeea Mon Sep 17 00:00:00 2001 From: martgil Date: Sun, 29 Sep 2024 18:49:23 +0800 Subject: [PATCH 5/5] refactor --- .../chrome/elements/compose-modules/compose-input-module.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extension/chrome/elements/compose-modules/compose-input-module.ts b/extension/chrome/elements/compose-modules/compose-input-module.ts index eb3aa1ec9e4..215b8adadf8 100644 --- a/extension/chrome/elements/compose-modules/compose-input-module.ts +++ b/extension/chrome/elements/compose-modules/compose-input-module.ts @@ -36,7 +36,7 @@ export class ComposeInputModule extends ViewModule { } public setHandlers = () => { - this.toggleRichTextFormatting(); + this.configureRichTextFormatting(); this.view.S.cached('add_intro').on( 'click', this.view.setHandler(el => this.actionAddIntroHandler(el), this.view.errModule.handle(`add intro`)) @@ -105,7 +105,7 @@ export class ComposeInputModule extends ViewModule { return isInputLimitExceeded; }; - private toggleRichTextFormatting = () => { + private configureRichTextFormatting = () => { if (this.isRichText()) { this.addRichTextFormatting(); } else {