From a7ab7034b51ca2316b8efb292d3e4b0f4665c2fa Mon Sep 17 00:00:00 2001 From: Dustin Stringer Date: Tue, 26 Sep 2023 22:44:07 -0400 Subject: [PATCH 1/2] Changed selection function to use ComposerUtils --- src/pages/home/report/ReportActionItemMessageEdit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionItemMessageEdit.js b/src/pages/home/report/ReportActionItemMessageEdit.js index 6ce826a2a34c..cea8a31b00c2 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.js +++ b/src/pages/home/report/ReportActionItemMessageEdit.js @@ -208,8 +208,8 @@ function ReportActionItemMessageEdit(props) { } setDraft((prevDraft) => { if (newDraftInput !== newDraft) { - setSelection((prevSelection) => { - const remainder = prevDraft.slice(prevSelection.end).length; + setSelection(() => { + const remainder = ComposerUtils.getCommonSuffixLength(prevDraft, newDraft); return { start: newDraft.length - remainder, end: newDraft.length - remainder, From bf5e21b14a65aad4fb5f647deeb5fe22b8f13ed9 Mon Sep 17 00:00:00 2001 From: Dustin Stringer Date: Tue, 26 Sep 2023 23:23:04 -0400 Subject: [PATCH 2/2] Refactored setSelection to not use previous value --- src/pages/home/report/ReportActionItemMessageEdit.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/pages/home/report/ReportActionItemMessageEdit.js b/src/pages/home/report/ReportActionItemMessageEdit.js index cea8a31b00c2..954af7a8d8a1 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.js +++ b/src/pages/home/report/ReportActionItemMessageEdit.js @@ -208,12 +208,10 @@ function ReportActionItemMessageEdit(props) { } setDraft((prevDraft) => { if (newDraftInput !== newDraft) { - setSelection(() => { - const remainder = ComposerUtils.getCommonSuffixLength(prevDraft, newDraft); - return { - start: newDraft.length - remainder, - end: newDraft.length - remainder, - }; + const remainder = ComposerUtils.getCommonSuffixLength(prevDraft, newDraft); + setSelection({ + start: newDraft.length - remainder, + end: newDraft.length - remainder, }); } return newDraft;