diff --git a/src/CONST.ts b/src/CONST.ts index 4a0b3e2b18e4..37f3b0e9ec15 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2395,6 +2395,7 @@ const CONST = { HAS_COLON_ONLY_AT_THE_BEGINNING: /^:[^:]+$/, HAS_AT_MOST_TWO_AT_SIGNS: /^@[^@]*@?[^@]*$/, + EMPTY_COMMENT: /^(\s)*$/, SPECIAL_CHAR: /[,/?"{}[\]()&^%;`$=#<>!*]/g, FIRST_SPACE: /.+?(?=\s)/, diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx index 085aa2f7db9a..21521396f347 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx @@ -481,24 +481,16 @@ function ComposerWithSuggestions( } // Trigger the edit box for last sent message if ArrowUp is pressed and the comment is empty and Chronos is not in the participants - const valueLength = valueRef.current.length; - if ( - 'key' in event && - event.key === CONST.KEYBOARD_SHORTCUTS.ARROW_UP.shortcutKey && - textInputRef.current && - 'selectionStart' in textInputRef.current && - textInputRef.current?.selectionStart === 0 && - valueLength === 0 && - !includeChronos - ) { - event.preventDefault(); + const isEmptyComment = !valueRef.current || !!valueRef.current.match(CONST.REGEX.EMPTY_COMMENT); + if (webEvent.key === CONST.KEYBOARD_SHORTCUTS.ARROW_UP.shortcutKey && selection.start <= 0 && isEmptyComment && !includeChronos) { + webEvent.preventDefault(); if (lastReportAction) { const message = Array.isArray(lastReportAction?.message) ? lastReportAction?.message?.at(-1) ?? null : lastReportAction?.message ?? null; Report.saveReportActionDraft(reportID, lastReportAction, Parser.htmlToMarkdown(message?.html ?? '')); } } }, - [shouldUseNarrowLayout, isKeyboardShown, suggestionsRef, includeChronos, handleSendMessage, lastReportAction, reportID], + [shouldUseNarrowLayout, isKeyboardShown, suggestionsRef, selection.start, includeChronos, handleSendMessage, lastReportAction, reportID], ); const onChangeText = useCallback( diff --git a/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx b/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx index 72e89c8de013..fd194040c1e6 100644 --- a/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx +++ b/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx @@ -179,7 +179,7 @@ function ReportActionCompose({ const [isCommentEmpty, setIsCommentEmpty] = useState(() => { const draftComment = getDraftComment(reportID); - return !draftComment || !!draftComment.match(/^(\s)*$/); + return !draftComment || !!draftComment.match(CONST.REGEX.EMPTY_COMMENT); }); /**