Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Edit messages by pressing ArrowUp #48585

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

/**
Expand Down
Loading