Skip to content

Commit ecc73ff

Browse files
iwizniaOSBotify
authored andcommitted
Merge pull request #48585 from fedirjh/Fix-selection-48549
[Fix] Edit messages by pressing ArrowUp (cherry picked from commit f890c73) (CP triggered by roryabraham)
1 parent 2afb4e7 commit ecc73ff

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

src/CONST.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2394,6 +2394,7 @@ const CONST = {
23942394
HAS_COLON_ONLY_AT_THE_BEGINNING: /^:[^:]+$/,
23952395
HAS_AT_MOST_TWO_AT_SIGNS: /^@[^@]*@?[^@]*$/,
23962396

2397+
EMPTY_COMMENT: /^(\s)*$/,
23972398
SPECIAL_CHAR: /[,/?"{}[\]()&^%;`$=#<>!*]/g,
23982399

23992400
FIRST_SPACE: /.+?(?=\s)/,

src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx

+4-12
Original file line numberDiff line numberDiff line change
@@ -481,24 +481,16 @@ function ComposerWithSuggestions(
481481
}
482482

483483
// Trigger the edit box for last sent message if ArrowUp is pressed and the comment is empty and Chronos is not in the participants
484-
const valueLength = valueRef.current.length;
485-
if (
486-
'key' in event &&
487-
event.key === CONST.KEYBOARD_SHORTCUTS.ARROW_UP.shortcutKey &&
488-
textInputRef.current &&
489-
'selectionStart' in textInputRef.current &&
490-
textInputRef.current?.selectionStart === 0 &&
491-
valueLength === 0 &&
492-
!includeChronos
493-
) {
494-
event.preventDefault();
484+
const isEmptyComment = !valueRef.current || !!valueRef.current.match(CONST.REGEX.EMPTY_COMMENT);
485+
if (webEvent.key === CONST.KEYBOARD_SHORTCUTS.ARROW_UP.shortcutKey && selection.start <= 0 && isEmptyComment && !includeChronos) {
486+
webEvent.preventDefault();
495487
if (lastReportAction) {
496488
const message = Array.isArray(lastReportAction?.message) ? lastReportAction?.message?.at(-1) ?? null : lastReportAction?.message ?? null;
497489
Report.saveReportActionDraft(reportID, lastReportAction, Parser.htmlToMarkdown(message?.html ?? ''));
498490
}
499491
}
500492
},
501-
[shouldUseNarrowLayout, isKeyboardShown, suggestionsRef, includeChronos, handleSendMessage, lastReportAction, reportID],
493+
[shouldUseNarrowLayout, isKeyboardShown, suggestionsRef, selection.start, includeChronos, handleSendMessage, lastReportAction, reportID],
502494
);
503495

504496
const onChangeText = useCallback(

src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ function ReportActionCompose({
179179

180180
const [isCommentEmpty, setIsCommentEmpty] = useState(() => {
181181
const draftComment = getDraftComment(reportID);
182-
return !draftComment || !!draftComment.match(/^(\s)*$/);
182+
return !draftComment || !!draftComment.match(CONST.REGEX.EMPTY_COMMENT);
183183
});
184184

185185
/**

0 commit comments

Comments
 (0)